@k13engineering/rubberband 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,25 @@
1
- /* c8 ignore start */
2
- import { loadAsBlob } from "esm-resource";
1
+ const isNode = typeof globalThis.process !== "undefined" &&
2
+ globalThis.process.versions !== null &&
3
+ globalThis.process.versions.node !== null;
4
+
5
+ const loadRubberbandWasmNodeJs = async () => {
6
+ const nodeFs = await import("fs");
7
+ const nodeUrl = await import("url");
8
+ const rubberbandWasmUrl = import.meta.resolve("rubberband-wasm/dist/rubberband.wasm");
9
+ const rubberbandWasmPath = nodeUrl.fileURLToPath(rubberbandWasmUrl);
10
+ const rubberbandWasm = await nodeFs.promises.readFile(rubberbandWasmPath);
11
+ return new Uint8Array(rubberbandWasm);
12
+ };
3
13
 
4
14
  const loadRubberbandWasm = async () => {
5
- const rubberbandBlob = await loadAsBlob({ importMeta: import.meta, filepath: "../../node_modules/rubberband-wasm/dist/rubberband.wasm" });
6
- const rubberbandWasmArrayBuffer = await rubberbandBlob.arrayBuffer();
7
- const rubberbandWasm = new Uint8Array(rubberbandWasmArrayBuffer);
8
- return rubberbandWasm;
15
+
16
+ if (isNode) {
17
+ return await loadRubberbandWasmNodeJs();
18
+ }
19
+
20
+ throw Error("browser environment not implemented yet");
9
21
  };
10
22
 
11
23
  export {
12
24
  loadRubberbandWasm
13
25
  };
14
- /* c8 ignore end */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.3",
2
+ "version": "0.0.5",
3
3
  "name": "@k13engineering/rubberband",
4
4
  "type": "module",
5
5
  "description": "Rubberband wrapper for Node.js",