taglib-wasm 1.0.0-beta.6 → 1.0.0-beta.8

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.
@@ -36,11 +36,11 @@ async function loadTagLibModule(options) {
36
36
  async function loadBufferModeTagLibModule(options) {
37
37
  let createTagLibModule;
38
38
  try {
39
- const module2 = await import("../../build/taglib-wrapper.js");
39
+ const module2 = await import("../../taglib-wrapper.js");
40
40
  createTagLibModule = module2.default;
41
41
  } catch {
42
42
  try {
43
- const module2 = await import("../../dist/taglib-wrapper.js");
43
+ const module2 = await import("../../taglib-wrapper.js");
44
44
  createTagLibModule = module2.default;
45
45
  } catch {
46
46
  throw new TagLibInitializationError(
@@ -59,6 +59,9 @@ async function loadBufferModeTagLibModule(options) {
59
59
  }
60
60
  return path;
61
61
  };
62
+ } else if (!options?.wasmBinary) {
63
+ const wasmUrl = new URL("../../build/taglib-web.wasm", import.meta.url);
64
+ moduleConfig.locateFile = (path) => path.endsWith(".wasm") ? wasmUrl.href : path;
62
65
  }
63
66
  const module = await createTagLibModule(moduleConfig);
64
67
  return module;
@@ -1 +1 @@
1
- {"version":3,"file":"module-loading.d.ts","sourceRoot":"","sources":["../../../../src/runtime/unified-loader/module-loading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGzE,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/B,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAS3B"}
1
+ {"version":3,"file":"module-loading.d.ts","sourceRoot":"","sources":["../../../../src/runtime/unified-loader/module-loading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAQzE,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/B,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAS3B"}
@@ -1,4 +1,8 @@
1
1
  import { ModuleLoadError } from "./types.js";
2
+ function resolveWasmPath(relativePath) {
3
+ const url = new URL(relativePath, import.meta.url);
4
+ return url.protocol === "file:" ? url.pathname : url.href;
5
+ }
2
6
  async function loadModule(wasmType, _runtime, options) {
3
7
  if (wasmType === "wasi") {
4
8
  return await loadWasiModuleWithFallback(options);
@@ -10,10 +14,11 @@ async function loadModule(wasmType, _runtime, options) {
10
14
  }
11
15
  }
12
16
  async function loadWasiModuleWithFallback(options) {
17
+ const defaultWasmPath = resolveWasmPath("../../../build/taglib_wasi.wasm");
13
18
  try {
14
19
  const { loadWasiHost } = await import("../wasi-host-loader.js");
15
20
  const wasiModule = await loadWasiHost({
16
- wasmPath: options.wasmUrl || "./dist/wasi/taglib_wasi.wasm"
21
+ wasmPath: options.wasmUrl || defaultWasmPath
17
22
  });
18
23
  return { module: wasiModule, actualWasmType: "wasi" };
19
24
  } catch (hostError) {
@@ -25,7 +30,7 @@ async function loadWasiModuleWithFallback(options) {
25
30
  const { initializeWasmer, loadWasmerWasi } = await import("../wasmer-sdk-loader/index.js");
26
31
  await initializeWasmer(options.useInlineWasm);
27
32
  const wasiModule = await loadWasmerWasi({
28
- wasmPath: options.wasmUrl || "./dist/taglib-wasi.wasm",
33
+ wasmPath: options.wasmUrl || defaultWasmPath,
29
34
  useInlineWasm: options.useInlineWasm,
30
35
  debug: options.debug
31
36
  });
@@ -47,11 +52,11 @@ async function loadEmscriptenModule(options) {
47
52
  try {
48
53
  let createModule;
49
54
  try {
50
- const module2 = await import("../../../build/taglib-wrapper.js");
55
+ const module2 = await import("../../../taglib-wrapper.js");
51
56
  createModule = module2.default;
52
57
  } catch {
53
58
  try {
54
- const module2 = await import("../../../dist/taglib-wrapper.js");
59
+ const module2 = await import("../../../taglib-wrapper.js");
55
60
  createModule = module2.default;
56
61
  } catch {
57
62
  throw new ModuleLoadError(
@@ -1 +1 @@
1
- {"version":3,"file":"wasm-io.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/wasm-io.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAOhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,UAAU,GACjB,UAAU,CAuCZ;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,WAAW,GACnB,UAAU,GAAG,IAAI,CAwCnB"}
1
+ {"version":3,"file":"wasm-io.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/wasm-io.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAOhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,UAAU,GACjB,UAAU,CA2BZ;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,WAAW,GACnB,UAAU,GAAG,IAAI,CAqBnB"}
@@ -54,36 +54,25 @@ function readTagsFromWasm(wasi, buffer) {
54
54
  const arena = __using(_stack, new WasmArena(wasi));
55
55
  const inputBuf = arena.allocBuffer(buffer);
56
56
  const outSizePtr = arena.allocUint32();
57
- const sizeResult = wasi.tl_read_tags(
57
+ const resultPtr = wasi.tl_read_tags(
58
58
  0,
59
59
  inputBuf.ptr,
60
60
  inputBuf.size,
61
61
  outSizePtr.ptr
62
62
  );
63
- if (sizeResult !== 0) {
63
+ if (resultPtr === 0) {
64
64
  const errorCode = wasi.tl_get_last_error_code();
65
65
  throw new WasmMemoryError(
66
- `error code ${errorCode}`,
67
- "read tags size",
66
+ `error code ${errorCode}. Buffer size: ${buffer.length} bytes`,
67
+ "read tags",
68
68
  errorCode
69
69
  );
70
70
  }
71
- const outputSize = outSizePtr.readUint32();
72
- const outputBuf = arena.alloc(outputSize);
73
- const readResult = wasi.tl_read_tags(
74
- 0,
75
- inputBuf.ptr,
76
- inputBuf.size,
77
- outputBuf.ptr
78
- );
79
- if (readResult !== 0) {
80
- throw new WasmMemoryError(
81
- "failed to read data into buffer",
82
- "read tags data",
83
- readResult
84
- );
85
- }
86
- return new Uint8Array(outputBuf.read().slice());
71
+ const outSize = outSizePtr.readUint32();
72
+ const u8 = new Uint8Array(wasi.memory.buffer);
73
+ const result = new Uint8Array(u8.slice(resultPtr, resultPtr + outSize));
74
+ wasi.free(resultPtr);
75
+ return result;
87
76
  } catch (_) {
88
77
  var _error = _, _hasError = true;
89
78
  } finally {
@@ -98,7 +87,7 @@ function writeTagsToWasm(wasi, fileData, tagData) {
98
87
  const inputBuf = arena.allocBuffer(fileData);
99
88
  const tagBuf = arena.allocBuffer(tagBytes);
100
89
  const outSizePtr = arena.allocUint32();
101
- const sizeResult = wasi.tl_write_tags(
90
+ const result = wasi.tl_write_tags(
102
91
  0,
103
92
  inputBuf.ptr,
104
93
  inputBuf.size,
@@ -107,23 +96,6 @@ function writeTagsToWasm(wasi, fileData, tagData) {
107
96
  0,
108
97
  outSizePtr.ptr
109
98
  );
110
- if (sizeResult !== 0) {
111
- return null;
112
- }
113
- const outputSize = outSizePtr.readUint32();
114
- const outputBuf = arena.alloc(outputSize);
115
- const writeResult = wasi.tl_write_tags(
116
- 0,
117
- inputBuf.ptr,
118
- inputBuf.size,
119
- tagBuf.ptr,
120
- tagBuf.size,
121
- outputBuf.ptr,
122
- outSizePtr.ptr
123
- );
124
- if (writeResult === 0) {
125
- return new Uint8Array(outputBuf.read().slice());
126
- }
127
99
  return null;
128
100
  } catch (_) {
129
101
  var _error = _, _hasError = true;
@@ -1 +1 @@
1
- {"version":3,"file":"wasi-host-loader.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-host-loader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE,kBAAkB,CAAC;CACzB;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAG,sBAAsB,CAAU;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAcD,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC,CAyClC"}
1
+ {"version":3,"file":"wasi-host-loader.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-host-loader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE,kBAAkB,CAAC;CACzB;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAG,sBAAsB,CAAU;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAcD,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC,CA6ClC"}
@@ -21,7 +21,11 @@ async function resolveFs(provided) {
21
21
  return createNodeFsProvider();
22
22
  }
23
23
  async function loadWasiHost(config) {
24
- const wasmPath = config.wasmPath ?? "./dist/wasi/taglib_wasi.wasm";
24
+ const defaultPath = (() => {
25
+ const url = new URL("../../build/taglib_wasi.wasm", import.meta.url);
26
+ return url.protocol === "file:" ? url.pathname : url.href;
27
+ })();
28
+ const wasmPath = config.wasmPath ?? defaultPath;
25
29
  const preopens = config.preopens ?? {};
26
30
  const fs = await resolveFs(config.fs);
27
31
  const wasmBytes = await loadWasmBinary(wasmPath, fs);
@@ -6,5 +6,5 @@ import type { WasiModule } from "./types.ts";
6
6
  * High-level API for reading tags from audio files using WASI
7
7
  * Uses RAII pattern with automatic memory cleanup
8
8
  */
9
- export declare function readTagsWithWasi(audioBuffer: Uint8Array, wasiModule: WasiModule): Promise<Uint8Array>;
9
+ export declare function readTagsWithWasi(audioBuffer: Uint8Array, wasiModule: WasiModule): Uint8Array;
10
10
  //# sourceMappingURL=high-level-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"high-level-api.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasmer-sdk-loader/high-level-api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,UAAU,EACvB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,CAAC,CA2CrB"}
1
+ {"version":3,"file":"high-level-api.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasmer-sdk-loader/high-level-api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,UAAU,EACvB,UAAU,EAAE,UAAU,GACrB,UAAU,CA2BZ"}
@@ -47,42 +47,31 @@ import {
47
47
  WasmArena,
48
48
  WasmMemoryError
49
49
  } from "../wasi-memory.js";
50
- async function readTagsWithWasi(audioBuffer, wasiModule) {
50
+ function readTagsWithWasi(audioBuffer, wasiModule) {
51
51
  var _stack = [];
52
52
  try {
53
53
  const arena = __using(_stack, new WasmArena(wasiModule));
54
54
  const inputBuf = arena.allocBuffer(audioBuffer);
55
55
  const outSizePtr = arena.allocUint32();
56
- const sizeResult = wasiModule.tl_read_tags(
56
+ const resultPtr = wasiModule.tl_read_tags(
57
57
  0,
58
58
  inputBuf.ptr,
59
59
  inputBuf.size,
60
60
  outSizePtr.ptr
61
61
  );
62
- if (sizeResult !== 0) {
62
+ if (resultPtr === 0) {
63
63
  const errorCode = wasiModule.tl_get_last_error_code();
64
64
  throw new WasmMemoryError(
65
- `error code ${errorCode}`,
66
- "read tags size",
65
+ `error code ${errorCode}. Buffer size: ${audioBuffer.length} bytes`,
66
+ "read tags",
67
67
  errorCode
68
68
  );
69
69
  }
70
- const outputSize = outSizePtr.readUint32();
71
- const outputBuf = arena.alloc(outputSize);
72
- const readResult = wasiModule.tl_read_tags(
73
- 0,
74
- inputBuf.ptr,
75
- inputBuf.size,
76
- outputBuf.ptr
77
- );
78
- if (readResult !== 0) {
79
- throw new WasmMemoryError(
80
- "failed to read data into buffer",
81
- "read tags data",
82
- readResult
83
- );
84
- }
85
- return new Uint8Array(outputBuf.read().slice());
70
+ const outSize = outSizePtr.readUint32();
71
+ const u8 = new Uint8Array(wasiModule.memory.buffer);
72
+ const result = new Uint8Array(u8.slice(resultPtr, resultPtr + outSize));
73
+ wasiModule.free(resultPtr);
74
+ return result;
86
75
  } catch (_) {
87
76
  var _error = _, _hasError = true;
88
77
  } finally {
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasmer-sdk-loader/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAMjE;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,UAAU,CAAC,CA6CrB"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasmer-sdk-loader/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAMjE;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,UAAU,CAAC,CAgDrB"}
@@ -5,7 +5,10 @@ import { instantiateWasi } from "./wasi-stubs.js";
5
5
  import { createWasiModule } from "./module-creation.js";
6
6
  async function loadWasmerWasi(config = {}) {
7
7
  const {
8
- wasmPath = "./dist/taglib-wasi.wasm",
8
+ wasmPath = (() => {
9
+ const url = new URL("../../../build/taglib_wasi.wasm", import.meta.url);
10
+ return url.protocol === "file:" ? url.pathname : url.href;
11
+ })(),
9
12
  useInlineWasm = false,
10
13
  mounts = {},
11
14
  env = {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taglib-wasm",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",