taglib-wasm 1.0.0-beta.2 → 1.0.0-beta.3
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.
- package/README.md +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/src/file-utils.js +7 -7
- package/dist/src/runtime/detector.d.ts +5 -4
- package/dist/src/runtime/detector.d.ts.map +1 -1
- package/dist/src/runtime/detector.js +15 -1
- package/dist/src/runtime/unified-loader.d.ts.map +1 -1
- package/dist/src/runtime/unified-loader.js +24 -17
- package/dist/src/runtime/wasi-fs-deno.d.ts +8 -0
- package/dist/src/runtime/wasi-fs-deno.d.ts.map +1 -0
- package/dist/src/runtime/wasi-fs-deno.js +26 -0
- package/dist/src/runtime/wasi-fs-node.d.ts +9 -0
- package/dist/src/runtime/wasi-fs-node.d.ts.map +1 -0
- package/dist/src/runtime/wasi-fs-node.js +60 -0
- package/dist/src/runtime/wasi-fs-provider.d.ts +25 -0
- package/dist/src/runtime/wasi-fs-provider.d.ts.map +1 -0
- package/dist/src/runtime/wasi-fs-provider.js +0 -0
- package/dist/src/runtime/wasi-host-loader.d.ts +2 -0
- package/dist/src/runtime/wasi-host-loader.d.ts.map +1 -1
- package/dist/src/runtime/wasi-host-loader.js +14 -3
- package/dist/src/runtime/wasi-host.d.ts +3 -1
- package/dist/src/runtime/wasi-host.d.ts.map +1 -1
- package/dist/src/runtime/wasi-host.js +12 -7
- package/dist/src/simple.d.ts +12 -12
- package/dist/src/simple.d.ts.map +1 -1
- package/dist/src/simple.js +8 -8
- package/dist/src/taglib/audio-file-base.d.ts +0 -1
- package/dist/src/taglib/audio-file-base.d.ts.map +1 -1
- package/dist/src/taglib/audio-file-base.js +30 -10
- package/dist/src/taglib/audio-file-impl.d.ts.map +1 -1
- package/dist/src/taglib/audio-file-impl.js +0 -1
- package/dist/src/taglib/mutable-tag.d.ts +7 -7
- package/dist/src/taglib/mutable-tag.d.ts.map +1 -1
- package/dist/src/taglib/taglib-class.d.ts +2 -0
- package/dist/src/taglib/taglib-class.d.ts.map +1 -1
- package/dist/src/taglib/taglib-class.js +14 -0
- package/dist/src/workers/taglib-worker.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -225,17 +225,17 @@ console.log(`Found ${duplicates.size} groups of duplicates`);
|
|
|
225
225
|
### Working with Cover Art
|
|
226
226
|
|
|
227
227
|
```typescript
|
|
228
|
-
import {
|
|
228
|
+
import { applyCoverArt, readCoverArt } from "taglib-wasm/simple";
|
|
229
229
|
|
|
230
230
|
// Extract cover art
|
|
231
|
-
const coverData = await
|
|
231
|
+
const coverData = await readCoverArt("song.mp3");
|
|
232
232
|
if (coverData) {
|
|
233
233
|
await Deno.writeFile("cover.jpg", coverData);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
// Set new cover art
|
|
237
237
|
const imageData = await Deno.readFile("new-cover.jpg");
|
|
238
|
-
const modifiedBuffer = await
|
|
238
|
+
const modifiedBuffer = await applyCoverArt("song.mp3", imageData, "image/jpeg");
|
|
239
239
|
// Save modifiedBuffer to file if needed
|
|
240
240
|
```
|
|
241
241
|
|
package/dist/index.d.ts
CHANGED
|
@@ -62,14 +62,14 @@ export type { TagLibErrorCode } from "./src/errors.ts";
|
|
|
62
62
|
* @see {@link readProperties} - Read audio properties
|
|
63
63
|
* @see {@link readPictures} - Read cover art/pictures
|
|
64
64
|
* @see {@link applyPictures} - Apply pictures to audio files
|
|
65
|
-
* @see {@link
|
|
66
|
-
* @see {@link
|
|
65
|
+
* @see {@link readCoverArt} - Read primary cover art data
|
|
66
|
+
* @see {@link applyCoverArt} - Apply primary cover art
|
|
67
67
|
* @see {@link readTagsBatch} - Read tags from multiple files efficiently
|
|
68
68
|
* @see {@link readPropertiesBatch} - Read properties from multiple files efficiently
|
|
69
69
|
* @see {@link readMetadataBatch} - Read complete metadata from multiple files efficiently
|
|
70
70
|
* @see {@link setWorkerPoolMode} - Enable/disable worker pool for Simple API
|
|
71
71
|
*/
|
|
72
|
-
export { addPicture, applyPictures, applyTags, type BatchOptions, type BatchResult, clearPictures, clearTags, findPictureByType,
|
|
72
|
+
export { addPicture, applyCoverArt, applyPictures, applyTags, type BatchOptions, type BatchResult, clearPictures, clearTags, findPictureByType, isValidAudioFile, readCoverArt, readFormat, readMetadataBatch, readPictureMetadata, readPictures, readProperties, readPropertiesBatch, readTags, readTagsBatch, replacePictureByType, setBufferMode, setSidecarConfig, setWorkerPoolMode, updateTags, } from "./src/simple.ts";
|
|
73
73
|
/**
|
|
74
74
|
* Enhanced property constants and utilities with rich metadata.
|
|
75
75
|
* @see {@link PROPERTIES} - Comprehensive property definitions with metadata
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;GAIG;AACH,OAAO,EAAE,aAAa,IAAI,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,yBAAyB,EACzB,sBAAsB,EACtB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,UAAU,EACV,aAAa,EACb,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;GAIG;AACH,OAAO,EAAE,aAAa,IAAI,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,yBAAyB,EACzB,sBAAsB,EACtB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;GAWG;AACH,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,EACV,IAAI,GACL,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EA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EACpB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,SAAS,EACT,OAAO,IAAI,aAAa,EACxB,WAAW,EACX,YAAY,EACZ,SAAS,EACT,MAAM,EACN,OAAO,GACR,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AAEH,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAyBvB"}
|
package/dist/index.js
CHANGED
|
@@ -24,16 +24,17 @@ import {
|
|
|
24
24
|
} from "./src/errors.js";
|
|
25
25
|
import {
|
|
26
26
|
addPicture,
|
|
27
|
+
applyCoverArt,
|
|
27
28
|
applyPictures,
|
|
28
29
|
applyTags,
|
|
29
30
|
clearPictures,
|
|
30
31
|
clearTags,
|
|
31
32
|
findPictureByType,
|
|
32
|
-
getCoverArt,
|
|
33
|
-
getFormat,
|
|
34
|
-
getPictureMetadata,
|
|
35
33
|
isValidAudioFile,
|
|
34
|
+
readCoverArt,
|
|
35
|
+
readFormat,
|
|
36
36
|
readMetadataBatch,
|
|
37
|
+
readPictureMetadata,
|
|
37
38
|
readPictures,
|
|
38
39
|
readProperties,
|
|
39
40
|
readPropertiesBatch,
|
|
@@ -41,7 +42,6 @@ import {
|
|
|
41
42
|
readTagsBatch,
|
|
42
43
|
replacePictureByType,
|
|
43
44
|
setBufferMode,
|
|
44
|
-
setCoverArt,
|
|
45
45
|
setSidecarConfig,
|
|
46
46
|
setWorkerPoolMode,
|
|
47
47
|
updateTags
|
|
@@ -190,6 +190,7 @@ export {
|
|
|
190
190
|
UnsupportedFormatError,
|
|
191
191
|
WorkerError,
|
|
192
192
|
addPicture,
|
|
193
|
+
applyCoverArt,
|
|
193
194
|
applyPictures,
|
|
194
195
|
applyTags,
|
|
195
196
|
canvasToPicture,
|
|
@@ -216,10 +217,7 @@ export {
|
|
|
216
217
|
getAllProperties,
|
|
217
218
|
getAllPropertyKeys,
|
|
218
219
|
getAllTagNames,
|
|
219
|
-
getCoverArt,
|
|
220
|
-
getFormat,
|
|
221
220
|
getGlobalWorkerPool,
|
|
222
|
-
getPictureMetadata,
|
|
223
221
|
getPropertiesByFormat,
|
|
224
222
|
getPropertyMetadata,
|
|
225
223
|
imageFileToPicture,
|
|
@@ -241,7 +239,10 @@ export {
|
|
|
241
239
|
loadPictureFromFile,
|
|
242
240
|
loadTagLibModule,
|
|
243
241
|
pictureToDataURL,
|
|
242
|
+
readCoverArt,
|
|
243
|
+
readFormat,
|
|
244
244
|
readMetadataBatch,
|
|
245
|
+
readPictureMetadata,
|
|
245
246
|
readPictures,
|
|
246
247
|
readProperties,
|
|
247
248
|
readPropertiesBatch,
|
|
@@ -251,7 +252,6 @@ export {
|
|
|
251
252
|
savePictureToFile,
|
|
252
253
|
scanFolder,
|
|
253
254
|
setBufferMode,
|
|
254
|
-
setCoverArt,
|
|
255
255
|
setCoverArtFromCanvas,
|
|
256
256
|
setSidecarConfig,
|
|
257
257
|
setWorkerPoolMode,
|
package/dist/src/file-utils.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { PICTURE_TYPE_VALUES } from "./types.js";
|
|
2
2
|
import {
|
|
3
|
+
applyCoverArt,
|
|
3
4
|
applyPictures,
|
|
4
|
-
|
|
5
|
+
readCoverArt,
|
|
5
6
|
readPictures,
|
|
6
|
-
replacePictureByType
|
|
7
|
-
setCoverArt
|
|
7
|
+
replacePictureByType
|
|
8
8
|
} from "./simple.js";
|
|
9
9
|
import { readFileData } from "./utils/file.js";
|
|
10
10
|
import { writeFileData } from "./utils/write.js";
|
|
11
11
|
async function exportCoverArt(audioPath, imagePath) {
|
|
12
|
-
const coverData = await
|
|
12
|
+
const coverData = await readCoverArt(audioPath);
|
|
13
13
|
if (!coverData) {
|
|
14
14
|
throw new Error(`No cover art found in: ${audioPath}`);
|
|
15
15
|
}
|
|
@@ -77,7 +77,7 @@ async function importCoverArt(audioPath, imagePath, options = {}) {
|
|
|
77
77
|
};
|
|
78
78
|
mimeType = mimeTypes[ext ?? ""] ?? "image/jpeg";
|
|
79
79
|
}
|
|
80
|
-
const modifiedBuffer = await
|
|
80
|
+
const modifiedBuffer = await applyCoverArt(audioPath, imageData, mimeType);
|
|
81
81
|
await writeFileData(audioPath, modifiedBuffer);
|
|
82
82
|
}
|
|
83
83
|
async function importPictureWithType(audioPath, imagePath, type, options = {}) {
|
|
@@ -138,7 +138,7 @@ async function copyCoverArt(sourcePath, targetPath, options = {}) {
|
|
|
138
138
|
const modifiedBuffer = await applyPictures(targetPath, pictures);
|
|
139
139
|
await writeFileData(targetPath, modifiedBuffer);
|
|
140
140
|
} else {
|
|
141
|
-
const coverData = await
|
|
141
|
+
const coverData = await readCoverArt(sourcePath);
|
|
142
142
|
if (!coverData) {
|
|
143
143
|
throw new Error(`No cover art found in: ${sourcePath}`);
|
|
144
144
|
}
|
|
@@ -146,7 +146,7 @@ async function copyCoverArt(sourcePath, targetPath, options = {}) {
|
|
|
146
146
|
const coverPicture = pictures.find(
|
|
147
147
|
(p) => p.type === PICTURE_TYPE_VALUES.FrontCover
|
|
148
148
|
) ?? pictures[0];
|
|
149
|
-
const modifiedBuffer = await
|
|
149
|
+
const modifiedBuffer = await applyCoverArt(
|
|
150
150
|
targetPath,
|
|
151
151
|
coverData,
|
|
152
152
|
coverPicture.mimeType
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Priority order:
|
|
9
9
|
* 1. Deno + WASI (optimal filesystem performance)
|
|
10
|
-
* 2.
|
|
11
|
-
* 3.
|
|
12
|
-
* 4.
|
|
10
|
+
* 2. Bun + WASI (via node:fs, check before Node)
|
|
11
|
+
* 3. Node.js + WASI (when available)
|
|
12
|
+
* 4. Browser + Emscripten (required for web)
|
|
13
|
+
* 5. Node.js + Emscripten (fallback compatibility)
|
|
13
14
|
*/
|
|
14
15
|
/**
|
|
15
16
|
* Supported runtime environments with their optimal WASM target
|
|
16
17
|
*/
|
|
17
|
-
export type RuntimeEnvironment = "deno-wasi" | "node-wasi" | "browser" | "node-emscripten" | "worker" | "cloudflare";
|
|
18
|
+
export type RuntimeEnvironment = "deno-wasi" | "node-wasi" | "bun-wasi" | "browser" | "node-emscripten" | "worker" | "cloudflare";
|
|
18
19
|
/**
|
|
19
20
|
* WASM binary types that can be loaded
|
|
20
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../../src/runtime/detector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../../src/runtime/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GACX,WAAW,GACX,UAAU,GACV,SAAS,GACT,iBAAiB,GACjB,QAAQ,GACR,YAAY,CAAC;AAEjB;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,YAAY,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,mCAAmC;IACnC,WAAW,EAAE,kBAAkB,CAAC;IAChC,oDAAoD;IACpD,QAAQ,EAAE,cAAc,CAAC;IACzB,kDAAkD;IAClD,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qDAAqD;IACrD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sDAAsD;IACtD,eAAe,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CAC5B;AA2ED;;GAEG;AACH,wBAAgB,aAAa,IAAI,sBAAsB,CAsFtD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAmBzE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAWjE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAGlE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,sBAAsB,CAG5D"}
|
|
@@ -20,6 +20,9 @@ function isCloudflareWorker() {
|
|
|
20
20
|
const globalAny = globalThis;
|
|
21
21
|
return typeof caches !== "undefined" && typeof Request !== "undefined" && typeof addEventListener === "function" && typeof Deno === "undefined" && typeof globalAny.process === "undefined";
|
|
22
22
|
}
|
|
23
|
+
function isBun() {
|
|
24
|
+
return typeof globalThis.Bun !== "undefined";
|
|
25
|
+
}
|
|
23
26
|
function isNode() {
|
|
24
27
|
const globalAny = globalThis;
|
|
25
28
|
return typeof globalAny.process !== "undefined" && globalAny.process.versions?.node !== void 0;
|
|
@@ -37,6 +40,15 @@ function detectRuntime() {
|
|
|
37
40
|
performanceTier: 1
|
|
38
41
|
};
|
|
39
42
|
}
|
|
43
|
+
if (isBun()) {
|
|
44
|
+
return {
|
|
45
|
+
environment: "bun-wasi",
|
|
46
|
+
wasmType: "wasi",
|
|
47
|
+
supportsFilesystem: true,
|
|
48
|
+
supportsStreaming: true,
|
|
49
|
+
performanceTier: 1
|
|
50
|
+
};
|
|
51
|
+
}
|
|
40
52
|
if (isNode() && hasWASISupport()) {
|
|
41
53
|
return {
|
|
42
54
|
environment: "node-wasi",
|
|
@@ -98,6 +110,8 @@ function getEnvironmentDescription(env) {
|
|
|
98
110
|
return "Deno with WASI (optimal filesystem performance)";
|
|
99
111
|
case "node-wasi":
|
|
100
112
|
return "Node.js with WASI (high performance)";
|
|
113
|
+
case "bun-wasi":
|
|
114
|
+
return "Bun with WASI (via node:fs)";
|
|
101
115
|
case "browser":
|
|
102
116
|
return "Browser with Emscripten (web compatibility)";
|
|
103
117
|
case "worker":
|
|
@@ -113,7 +127,7 @@ function getEnvironmentDescription(env) {
|
|
|
113
127
|
function canLoadWasmType(wasmType) {
|
|
114
128
|
const result = detectRuntime();
|
|
115
129
|
if (wasmType === "wasi") {
|
|
116
|
-
return result.environment === "deno-wasi" || result.environment === "node-wasi";
|
|
130
|
+
return result.environment === "deno-wasi" || result.environment === "node-wasi" || result.environment === "bun-wasi";
|
|
117
131
|
}
|
|
118
132
|
return true;
|
|
119
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-loader.d.ts","sourceRoot":"","sources":["../../../src/runtime/unified-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"unified-loader.d.ts","sourceRoot":"","sources":["../../../src/runtime/unified-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAG,sBAAsB,CAAU;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK7C;AAED,qBAAa,eAAgB,SAAQ,KAAK;aAItB,QAAQ,EAAE,MAAM,GAAG,YAA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p = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { detectRuntime } from "./detector.js";
|
|
5
|
-
import {
|
|
6
|
-
initializeWasmer,
|
|
7
|
-
isWasmerAvailable,
|
|
8
|
-
loadWasmerWasi
|
|
9
|
-
} from "./wasmer-sdk-loader.js";
|
|
10
5
|
class UnifiedLoaderError extends Error {
|
|
11
6
|
constructor(message, cause) {
|
|
12
7
|
super(message);
|
|
@@ -30,7 +25,7 @@ async function loadUnifiedTagLibModule(options = {}) {
|
|
|
30
25
|
if (options.debug) {
|
|
31
26
|
console.log(`[UnifiedLoader] Detected runtime: ${runtime.environment}`);
|
|
32
27
|
}
|
|
33
|
-
const wasmType =
|
|
28
|
+
const wasmType = selectWasmType(runtime, options);
|
|
34
29
|
if (options.debug) {
|
|
35
30
|
console.log(
|
|
36
31
|
`[UnifiedLoader] Selected ${wasmType} for ${runtime.environment}`
|
|
@@ -53,14 +48,14 @@ async function loadUnifiedTagLibModule(options = {}) {
|
|
|
53
48
|
}
|
|
54
49
|
return unifiedModule;
|
|
55
50
|
}
|
|
56
|
-
|
|
51
|
+
function selectWasmType(runtime, options) {
|
|
57
52
|
if (options.forceWasmType) {
|
|
58
53
|
return options.forceWasmType;
|
|
59
54
|
}
|
|
60
55
|
if (options.disableOptimizations) {
|
|
61
56
|
return "emscripten";
|
|
62
57
|
}
|
|
63
|
-
if (runtime.
|
|
58
|
+
if (runtime.wasmType === "wasi" && runtime.supportsFilesystem) {
|
|
64
59
|
return "wasi";
|
|
65
60
|
}
|
|
66
61
|
return "emscripten";
|
|
@@ -77,6 +72,18 @@ async function loadModule(wasmType, _runtime, options) {
|
|
|
77
72
|
}
|
|
78
73
|
async function loadWasiModuleWithFallback(options) {
|
|
79
74
|
try {
|
|
75
|
+
const { loadWasiHost } = await import("./wasi-host-loader.js");
|
|
76
|
+
const wasiModule = await loadWasiHost({
|
|
77
|
+
wasmPath: options.wasmUrl || "./dist/wasi/taglib_wasi.wasm"
|
|
78
|
+
});
|
|
79
|
+
return { module: wasiModule, actualWasmType: "wasi" };
|
|
80
|
+
} catch (hostError) {
|
|
81
|
+
if (options.debug) {
|
|
82
|
+
console.warn(`[UnifiedLoader] WASI host failed:`, hostError);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const { initializeWasmer, loadWasmerWasi } = await import("./wasmer-sdk-loader.js");
|
|
80
87
|
await initializeWasmer(options.useInlineWasm);
|
|
81
88
|
const wasiModule = await loadWasmerWasi({
|
|
82
89
|
wasmPath: options.wasmUrl || "./dist/taglib-wasi.wasm",
|
|
@@ -84,18 +91,18 @@ async function loadWasiModuleWithFallback(options) {
|
|
|
84
91
|
debug: options.debug
|
|
85
92
|
});
|
|
86
93
|
return { module: wasiModule, actualWasmType: "wasi" };
|
|
87
|
-
} catch (
|
|
94
|
+
} catch (sdkError) {
|
|
88
95
|
if (options.debug) {
|
|
89
|
-
console.warn(
|
|
90
|
-
`[UnifiedLoader] WASI loading failed, falling back to Emscripten:`,
|
|
91
|
-
error
|
|
92
|
-
);
|
|
96
|
+
console.warn(`[UnifiedLoader] Wasmer SDK failed:`, sdkError);
|
|
93
97
|
}
|
|
94
|
-
return {
|
|
95
|
-
module: await loadEmscriptenModule(options),
|
|
96
|
-
actualWasmType: "emscripten"
|
|
97
|
-
};
|
|
98
98
|
}
|
|
99
|
+
if (options.debug) {
|
|
100
|
+
console.warn(`[UnifiedLoader] All WASI loaders failed, using Emscripten`);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
module: await loadEmscriptenModule(options),
|
|
104
|
+
actualWasmType: "emscripten"
|
|
105
|
+
};
|
|
99
106
|
}
|
|
100
107
|
async function loadEmscriptenModule(options) {
|
|
101
108
|
try {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Deno filesystem provider for WASI host
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper mapping Deno APIs to the FileSystemProvider interface.
|
|
5
|
+
*/
|
|
6
|
+
import type { FileSystemProvider } from "./wasi-fs-provider.ts";
|
|
7
|
+
export declare function createDenoFsProvider(): FileSystemProvider;
|
|
8
|
+
//# sourceMappingURL=wasi-fs-deno.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasi-fs-deno.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-fs-deno.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,uBAAuB,CAAC;AAa/B,wBAAgB,oBAAoB,IAAI,kBAAkB,CAazD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function wrapDenoFile(file) {
|
|
2
|
+
return {
|
|
3
|
+
readSync: (target) => file.readSync(target),
|
|
4
|
+
writeSync: (data) => file.writeSync(data),
|
|
5
|
+
seekSync: (offset, whence) => file.seekSync(offset, whence),
|
|
6
|
+
truncateSync: (size) => file.truncateSync(size),
|
|
7
|
+
close: () => file.close()
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function createDenoFsProvider() {
|
|
11
|
+
return {
|
|
12
|
+
openSync(path, options) {
|
|
13
|
+
const file = Deno.openSync(path, options);
|
|
14
|
+
return wrapDenoFile(file);
|
|
15
|
+
},
|
|
16
|
+
readFile(path) {
|
|
17
|
+
return Deno.readFile(path);
|
|
18
|
+
},
|
|
19
|
+
isNotFoundError(error) {
|
|
20
|
+
return error instanceof Deno.errors.NotFound;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
createDenoFsProvider
|
|
26
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Node.js/Bun filesystem provider for WASI host
|
|
3
|
+
*
|
|
4
|
+
* Uses node:fs with manual position tracking since Node lacks seekSync.
|
|
5
|
+
* Bun implements node:fs faithfully, so this provider covers both.
|
|
6
|
+
*/
|
|
7
|
+
import type { FileSystemProvider } from "./wasi-fs-provider.ts";
|
|
8
|
+
export declare function createNodeFsProvider(): Promise<FileSystemProvider>;
|
|
9
|
+
//# sourceMappingURL=wasi-fs-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasi-fs-node.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-fs-node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,uBAAuB,CAAC;AA+C/B,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAiBxE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function mapOpenFlags(options) {
|
|
2
|
+
if (options.create && options.truncate) return "w+";
|
|
3
|
+
if (options.create) return "a+";
|
|
4
|
+
if (options.write) return "r+";
|
|
5
|
+
return "r";
|
|
6
|
+
}
|
|
7
|
+
function createNodeFileHandle(fs, fd) {
|
|
8
|
+
let position = 0;
|
|
9
|
+
return {
|
|
10
|
+
readSync(target) {
|
|
11
|
+
const n = fs.readSync(fd, target, 0, target.length, position);
|
|
12
|
+
if (n === 0) return null;
|
|
13
|
+
position += n;
|
|
14
|
+
return n;
|
|
15
|
+
},
|
|
16
|
+
writeSync(data) {
|
|
17
|
+
const n = fs.writeSync(fd, data, 0, data.length, position);
|
|
18
|
+
position += n;
|
|
19
|
+
return n;
|
|
20
|
+
},
|
|
21
|
+
seekSync(offset, whence) {
|
|
22
|
+
if (whence === 0) {
|
|
23
|
+
position = offset;
|
|
24
|
+
} else if (whence === 1) {
|
|
25
|
+
position += offset;
|
|
26
|
+
} else {
|
|
27
|
+
const stat = fs.fstatSync(fd);
|
|
28
|
+
position = stat.size + offset;
|
|
29
|
+
}
|
|
30
|
+
if (position < 0) throw new Error(`Invalid seek position: ${position}`);
|
|
31
|
+
return position;
|
|
32
|
+
},
|
|
33
|
+
truncateSync(size) {
|
|
34
|
+
fs.ftruncateSync(fd, size);
|
|
35
|
+
},
|
|
36
|
+
close() {
|
|
37
|
+
fs.closeSync(fd);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function createNodeFsProvider() {
|
|
42
|
+
const fs = await import("node:fs");
|
|
43
|
+
const fsp = await import("node:fs/promises");
|
|
44
|
+
return {
|
|
45
|
+
openSync(path, options) {
|
|
46
|
+
const flags = mapOpenFlags(options);
|
|
47
|
+
const fd = fs.openSync(path, flags);
|
|
48
|
+
return createNodeFileHandle(fs, fd);
|
|
49
|
+
},
|
|
50
|
+
async readFile(path) {
|
|
51
|
+
return new Uint8Array(await fsp.readFile(path));
|
|
52
|
+
},
|
|
53
|
+
isNotFoundError(error) {
|
|
54
|
+
return error?.code === "ENOENT";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
createNodeFsProvider
|
|
60
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Filesystem provider interface for runtime-agnostic WASI host
|
|
3
|
+
*
|
|
4
|
+
* Abstracts the 6 file operations needed by WASI syscalls so that
|
|
5
|
+
* Deno, Node.js, and Bun can all use seek-based I/O.
|
|
6
|
+
*/
|
|
7
|
+
export type WasiFileHandle = {
|
|
8
|
+
readSync(target: Uint8Array): number | null;
|
|
9
|
+
writeSync(data: Uint8Array): number;
|
|
10
|
+
seekSync(offset: number, whence: 0 | 1 | 2): number;
|
|
11
|
+
truncateSync(size: number): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
14
|
+
export type WasiOpenOptions = {
|
|
15
|
+
read: boolean;
|
|
16
|
+
write: boolean;
|
|
17
|
+
create?: boolean;
|
|
18
|
+
truncate?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type FileSystemProvider = {
|
|
21
|
+
openSync(path: string, options: WasiOpenOptions): WasiFileHandle;
|
|
22
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
23
|
+
isNotFoundError(error: unknown): boolean;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=wasi-fs-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasi-fs-provider.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-fs-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5C,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;IACpD,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,cAAc,CAAC;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5C,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAC1C,CAAC"}
|
|
File without changes
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* implementations, enabling efficient seek-based file I/O without
|
|
6
6
|
* the Wasmtime sidecar subprocess.
|
|
7
7
|
*/
|
|
8
|
+
import type { FileSystemProvider } from "./wasi-fs-provider.ts";
|
|
8
9
|
import type { WasiModule } from "./wasmer-sdk-loader.ts";
|
|
9
10
|
export interface WasiHostLoaderConfig {
|
|
10
11
|
wasmPath?: string;
|
|
11
12
|
preopens?: Record<string, string>;
|
|
13
|
+
fs?: FileSystemProvider;
|
|
12
14
|
}
|
|
13
15
|
export declare class WasiHostLoadError extends Error {
|
|
14
16
|
readonly code: "WASI_HOST_LOAD_ERROR";
|
|
@@ -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,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
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,wBAAwB,CAAC;AAEzD,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"}
|
|
@@ -11,14 +11,25 @@ class WasiHostLoadError extends Error {
|
|
|
11
11
|
this.name = "WasiHostLoadError";
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
async function resolveFs(provided) {
|
|
15
|
+
if (provided) return provided;
|
|
16
|
+
if (typeof Deno !== "undefined") {
|
|
17
|
+
const { createDenoFsProvider } = await import("./wasi-fs-deno.js");
|
|
18
|
+
return createDenoFsProvider();
|
|
19
|
+
}
|
|
20
|
+
const { createNodeFsProvider } = await import("./wasi-fs-node.js");
|
|
21
|
+
return createNodeFsProvider();
|
|
22
|
+
}
|
|
14
23
|
async function loadWasiHost(config) {
|
|
15
24
|
const wasmPath = config.wasmPath ?? "./dist/wasi/taglib_wasi.wasm";
|
|
16
25
|
const preopens = config.preopens ?? {};
|
|
17
|
-
const
|
|
26
|
+
const fs = await resolveFs(config.fs);
|
|
27
|
+
const wasmBytes = await loadWasmBinary(wasmPath, fs);
|
|
18
28
|
const wasmModule = await WebAssembly.compile(wasmBytes);
|
|
19
29
|
const memoryProxy = { buffer: new ArrayBuffer(0) };
|
|
20
30
|
const hostConfig = {
|
|
21
31
|
preopens,
|
|
32
|
+
fs,
|
|
22
33
|
stderr: (data) => {
|
|
23
34
|
const text = new TextDecoder().decode(data);
|
|
24
35
|
if (text.trim()) console.error(`[wasi-host] ${text}`);
|
|
@@ -39,7 +50,7 @@ async function loadWasiHost(config) {
|
|
|
39
50
|
}
|
|
40
51
|
return createWasiModuleFromInstance(instance, memory, wasiImports);
|
|
41
52
|
}
|
|
42
|
-
async function loadWasmBinary(path) {
|
|
53
|
+
async function loadWasmBinary(path, fs) {
|
|
43
54
|
if (path.startsWith("http://") || path.startsWith("https://")) {
|
|
44
55
|
const response = await fetch(path);
|
|
45
56
|
if (!response.ok) {
|
|
@@ -50,7 +61,7 @@ async function loadWasmBinary(path) {
|
|
|
50
61
|
return new Uint8Array(await response.arrayBuffer());
|
|
51
62
|
}
|
|
52
63
|
try {
|
|
53
|
-
return await
|
|
64
|
+
return await fs.readFile(path);
|
|
54
65
|
} catch (cause) {
|
|
55
66
|
throw new WasiHostLoadError(
|
|
56
67
|
`Failed to read Wasm binary: ${path}`,
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* @fileoverview WASI P1 syscall implementations backed by real filesystem
|
|
3
3
|
*
|
|
4
4
|
* Provides synchronous WASI imports for in-process Wasm execution.
|
|
5
|
-
* Uses
|
|
5
|
+
* Uses a FileSystemProvider for runtime-agnostic file operations.
|
|
6
6
|
*/
|
|
7
|
+
import type { FileSystemProvider } from "./wasi-fs-provider.ts";
|
|
7
8
|
export interface WasiHostConfig {
|
|
8
9
|
preopens: Record<string, string>;
|
|
10
|
+
fs: FileSystemProvider;
|
|
9
11
|
stdout?: (data: Uint8Array) => void;
|
|
10
12
|
stderr?: (data: Uint8Array) => void;
|
|
11
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasi-host.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-host.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACrC;AAaD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;CAAE,CAAC;AAE9E,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,EAC/B,MAAM,EAAE,cAAc,GACrB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"wasi-host.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-host.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAEhF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,EAAE,EAAE,kBAAkB,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACrC;AAaD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;CAAE,CAAC;AAE9E,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,EAC/B,MAAM,EAAE,cAAc,GACrB,oBAAoB,CA0PtB"}
|
|
@@ -109,9 +109,11 @@ function createWasiImports(memory, config) {
|
|
|
109
109
|
fd_seek: (fd, offset, whence, newoffsetPtr) => {
|
|
110
110
|
const entry = fds.get(fd);
|
|
111
111
|
if (!entry || entry.type !== "file") return WASI_EBADF;
|
|
112
|
-
const seekMode = whence === 0 ? Deno.SeekMode.Start : whence === 1 ? Deno.SeekMode.Current : Deno.SeekMode.End;
|
|
113
112
|
try {
|
|
114
|
-
const newPos = entry.file.seekSync(
|
|
113
|
+
const newPos = entry.file.seekSync(
|
|
114
|
+
Number(offset),
|
|
115
|
+
whence
|
|
116
|
+
);
|
|
115
117
|
const { dv } = getMemory();
|
|
116
118
|
dv.setBigInt64(newoffsetPtr, BigInt(newPos), true);
|
|
117
119
|
return WASI_ESUCCESS;
|
|
@@ -149,17 +151,20 @@ function createWasiImports(memory, config) {
|
|
|
149
151
|
const RIGHTS_FD_WRITE = 1n << 6n;
|
|
150
152
|
try {
|
|
151
153
|
const wantWrite = (_rightsBase & RIGHTS_FD_WRITE) !== 0n || (oflags & (OFLAGS_CREAT | OFLAGS_TRUNC)) !== 0;
|
|
152
|
-
const options = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
const options = {
|
|
155
|
+
read: true,
|
|
156
|
+
write: wantWrite,
|
|
157
|
+
create: (oflags & OFLAGS_CREAT) !== 0,
|
|
158
|
+
truncate: (oflags & OFLAGS_TRUNC) !== 0
|
|
159
|
+
};
|
|
160
|
+
const file = config.fs.openSync(realPath, options);
|
|
156
161
|
const fd = nextFd++;
|
|
157
162
|
fds.set(fd, { type: "file", file, path: realPath });
|
|
158
163
|
const { dv } = getMemory();
|
|
159
164
|
dv.setUint32(openedFdPtr, fd, true);
|
|
160
165
|
return WASI_ESUCCESS;
|
|
161
166
|
} catch (e) {
|
|
162
|
-
if (
|
|
167
|
+
if (config.fs.isNotFoundError(e)) return WASI_ENOENT;
|
|
163
168
|
return WASI_EINVAL;
|
|
164
169
|
}
|
|
165
170
|
},
|
package/dist/src/simple.d.ts
CHANGED
|
@@ -205,18 +205,18 @@ export declare const DiscNumber = "discnumber";
|
|
|
205
205
|
*/
|
|
206
206
|
export declare function isValidAudioFile(file: string | Uint8Array | ArrayBuffer | File): Promise<boolean>;
|
|
207
207
|
/**
|
|
208
|
-
*
|
|
208
|
+
* Read the audio format of a file
|
|
209
209
|
*
|
|
210
210
|
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
211
211
|
* @returns Audio format string (e.g., "MP3", "FLAC", "OGG") or undefined
|
|
212
212
|
*
|
|
213
213
|
* @example
|
|
214
214
|
* ```typescript
|
|
215
|
-
* const format = await
|
|
215
|
+
* const format = await readFormat("song.mp3");
|
|
216
216
|
* console.log(`File format: ${format}`); // "MP3"
|
|
217
217
|
* ```
|
|
218
218
|
*/
|
|
219
|
-
export declare function
|
|
219
|
+
export declare function readFormat(file: string | Uint8Array | ArrayBuffer | File): Promise<string | undefined>;
|
|
220
220
|
/**
|
|
221
221
|
* Clear all tags from a file
|
|
222
222
|
*
|
|
@@ -303,7 +303,7 @@ export declare function addPicture(file: string | Uint8Array | ArrayBuffer | Fil
|
|
|
303
303
|
*/
|
|
304
304
|
export declare function clearPictures(file: string | Uint8Array | ArrayBuffer | File): Promise<Uint8Array>;
|
|
305
305
|
/**
|
|
306
|
-
*
|
|
306
|
+
* Read the primary cover art from an audio file
|
|
307
307
|
*
|
|
308
308
|
* Returns the front cover if available, otherwise the first picture found.
|
|
309
309
|
* Returns null if no pictures are present.
|
|
@@ -313,15 +313,15 @@ export declare function clearPictures(file: string | Uint8Array | ArrayBuffer |
|
|
|
313
313
|
*
|
|
314
314
|
* @example
|
|
315
315
|
* ```typescript
|
|
316
|
-
* const coverArt = await
|
|
316
|
+
* const coverArt = await readCoverArt("song.mp3");
|
|
317
317
|
* if (coverArt) {
|
|
318
318
|
* console.log(`Cover art size: ${coverArt.length} bytes`);
|
|
319
319
|
* }
|
|
320
320
|
* ```
|
|
321
321
|
*/
|
|
322
|
-
export declare function
|
|
322
|
+
export declare function readCoverArt(file: string | Uint8Array | ArrayBuffer | File): Promise<Uint8Array | null>;
|
|
323
323
|
/**
|
|
324
|
-
*
|
|
324
|
+
* Apply primary cover art to an audio file and return the modified buffer
|
|
325
325
|
*
|
|
326
326
|
* Replaces all existing pictures with a single front cover image.
|
|
327
327
|
*
|
|
@@ -333,10 +333,10 @@ export declare function getCoverArt(file: string | Uint8Array | ArrayBuffer | Fi
|
|
|
333
333
|
* @example
|
|
334
334
|
* ```typescript
|
|
335
335
|
* const jpegData = await Deno.readFile("cover.jpg");
|
|
336
|
-
* const modifiedBuffer = await
|
|
336
|
+
* const modifiedBuffer = await applyCoverArt("song.mp3", jpegData, "image/jpeg");
|
|
337
337
|
* ```
|
|
338
338
|
*/
|
|
339
|
-
export declare function
|
|
339
|
+
export declare function applyCoverArt(file: string | Uint8Array | ArrayBuffer | File, imageData: Uint8Array, mimeType: string): Promise<Uint8Array>;
|
|
340
340
|
/**
|
|
341
341
|
* Find a picture by its type
|
|
342
342
|
*
|
|
@@ -377,7 +377,7 @@ export declare function findPictureByType(pictures: Picture[], type: PictureType
|
|
|
377
377
|
*/
|
|
378
378
|
export declare function replacePictureByType(file: string | Uint8Array | ArrayBuffer | File, newPicture: Picture): Promise<Uint8Array>;
|
|
379
379
|
/**
|
|
380
|
-
*
|
|
380
|
+
* Read picture metadata without the actual image data
|
|
381
381
|
*
|
|
382
382
|
* Useful for checking what pictures are present without loading
|
|
383
383
|
* potentially large image data into memory.
|
|
@@ -387,13 +387,13 @@ export declare function replacePictureByType(file: string | Uint8Array | ArrayBu
|
|
|
387
387
|
*
|
|
388
388
|
* @example
|
|
389
389
|
* ```typescript
|
|
390
|
-
* const metadata = await
|
|
390
|
+
* const metadata = await readPictureMetadata("song.mp3");
|
|
391
391
|
* for (const info of metadata) {
|
|
392
392
|
* console.log(`${info.description}: ${info.mimeType}, ${info.size} bytes`);
|
|
393
393
|
* }
|
|
394
394
|
* ```
|
|
395
395
|
*/
|
|
396
|
-
export declare function
|
|
396
|
+
export declare function readPictureMetadata(file: string | Uint8Array | ArrayBuffer | File): Promise<Array<{
|
|
397
397
|
type: number;
|
|
398
398
|
mimeType: string;
|
|
399
399
|
description?: string;
|
package/dist/src/simple.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../../src/simple.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,OAAO,EACP,WAAW,EACX,GAAG,EACJ,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AAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/src/simple.js
CHANGED
|
@@ -169,7 +169,7 @@ async function isValidAudioFile(file) {
|
|
|
169
169
|
return false;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
async function
|
|
172
|
+
async function readFormat(file) {
|
|
173
173
|
const taglib = await getTagLib();
|
|
174
174
|
const audioFile = await taglib.open(file);
|
|
175
175
|
try {
|
|
@@ -254,7 +254,7 @@ async function addPicture(file, picture) {
|
|
|
254
254
|
async function clearPictures(file) {
|
|
255
255
|
return applyPictures(file, []);
|
|
256
256
|
}
|
|
257
|
-
async function
|
|
257
|
+
async function readCoverArt(file) {
|
|
258
258
|
const pictures = await readPictures(file);
|
|
259
259
|
if (pictures.length === 0) {
|
|
260
260
|
return null;
|
|
@@ -267,7 +267,7 @@ async function getCoverArt(file) {
|
|
|
267
267
|
}
|
|
268
268
|
return pictures[0].data;
|
|
269
269
|
}
|
|
270
|
-
async function
|
|
270
|
+
async function applyCoverArt(file, imageData, mimeType) {
|
|
271
271
|
if (useWorkerPool && workerPoolInstance && (typeof file === "string" || file instanceof Uint8Array)) {
|
|
272
272
|
return workerPoolInstance.setCoverArt(file, imageData, mimeType);
|
|
273
273
|
}
|
|
@@ -291,7 +291,7 @@ async function replacePictureByType(file, newPicture) {
|
|
|
291
291
|
filteredPictures.push(newPicture);
|
|
292
292
|
return applyPictures(file, filteredPictures);
|
|
293
293
|
}
|
|
294
|
-
async function
|
|
294
|
+
async function readPictureMetadata(file) {
|
|
295
295
|
const pictures = await readPictures(file);
|
|
296
296
|
return pictures.map((pic) => ({
|
|
297
297
|
type: pic.type,
|
|
@@ -502,16 +502,17 @@ export {
|
|
|
502
502
|
Track,
|
|
503
503
|
Year,
|
|
504
504
|
addPicture,
|
|
505
|
+
applyCoverArt,
|
|
505
506
|
applyPictures,
|
|
506
507
|
applyTags,
|
|
507
508
|
clearPictures,
|
|
508
509
|
clearTags,
|
|
509
510
|
findPictureByType,
|
|
510
|
-
getCoverArt,
|
|
511
|
-
getFormat,
|
|
512
|
-
getPictureMetadata,
|
|
513
511
|
isValidAudioFile,
|
|
512
|
+
readCoverArt,
|
|
513
|
+
readFormat,
|
|
514
514
|
readMetadataBatch,
|
|
515
|
+
readPictureMetadata,
|
|
515
516
|
readPictures,
|
|
516
517
|
readProperties,
|
|
517
518
|
readPropertiesBatch,
|
|
@@ -519,7 +520,6 @@ export {
|
|
|
519
520
|
readTagsBatch,
|
|
520
521
|
replacePictureByType,
|
|
521
522
|
setBufferMode,
|
|
522
|
-
setCoverArt,
|
|
523
523
|
setSidecarConfig,
|
|
524
524
|
setWorkerPoolMode,
|
|
525
525
|
updateTags
|
|
@@ -10,7 +10,6 @@ import type { MutableTag } from "./mutable-tag.ts";
|
|
|
10
10
|
export declare abstract class BaseAudioFileImpl {
|
|
11
11
|
protected readonly module: TagLibModule;
|
|
12
12
|
protected fileHandle: any;
|
|
13
|
-
protected cachedTag: MutableTag | null;
|
|
14
13
|
protected cachedAudioProperties: AudioProperties | null;
|
|
15
14
|
protected readonly sourcePath?: string;
|
|
16
15
|
protected originalSource?: AudioFileInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-file-base.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,QAAQ,EACR,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;GAKG;AACH,8BAAsB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"audio-file-base.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-base.ts"],"names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KAAK,EAAE,MAAM,GAAG,IAAI;IAO5C,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOhC,OAAO,IAAI,OAAO;IAIlB,OAAO,IAAI,IAAI;IAUf,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
|
@@ -6,7 +6,6 @@ class BaseAudioFileImpl {
|
|
|
6
6
|
constructor(module, fileHandle, sourcePath, originalSource, isPartiallyLoaded = false, partialLoadOptions) {
|
|
7
7
|
this.module = module;
|
|
8
8
|
__publicField(this, "fileHandle");
|
|
9
|
-
__publicField(this, "cachedTag", null);
|
|
10
9
|
__publicField(this, "cachedAudioProperties", null);
|
|
11
10
|
__publicField(this, "sourcePath");
|
|
12
11
|
__publicField(this, "originalSource");
|
|
@@ -29,7 +28,7 @@ class BaseAudioFileImpl {
|
|
|
29
28
|
"Tag may be corrupted or format not fully supported"
|
|
30
29
|
);
|
|
31
30
|
}
|
|
32
|
-
|
|
31
|
+
const tag = {
|
|
33
32
|
title: tagWrapper.title(),
|
|
34
33
|
artist: tagWrapper.artist(),
|
|
35
34
|
album: tagWrapper.album(),
|
|
@@ -37,14 +36,36 @@ class BaseAudioFileImpl {
|
|
|
37
36
|
genre: tagWrapper.genre(),
|
|
38
37
|
year: tagWrapper.year(),
|
|
39
38
|
track: tagWrapper.track(),
|
|
40
|
-
setTitle: (value) =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
setTitle: (value) => {
|
|
40
|
+
tagWrapper.setTitle(value);
|
|
41
|
+
return tag;
|
|
42
|
+
},
|
|
43
|
+
setArtist: (value) => {
|
|
44
|
+
tagWrapper.setArtist(value);
|
|
45
|
+
return tag;
|
|
46
|
+
},
|
|
47
|
+
setAlbum: (value) => {
|
|
48
|
+
tagWrapper.setAlbum(value);
|
|
49
|
+
return tag;
|
|
50
|
+
},
|
|
51
|
+
setComment: (value) => {
|
|
52
|
+
tagWrapper.setComment(value);
|
|
53
|
+
return tag;
|
|
54
|
+
},
|
|
55
|
+
setGenre: (value) => {
|
|
56
|
+
tagWrapper.setGenre(value);
|
|
57
|
+
return tag;
|
|
58
|
+
},
|
|
59
|
+
setYear: (value) => {
|
|
60
|
+
tagWrapper.setYear(value);
|
|
61
|
+
return tag;
|
|
62
|
+
},
|
|
63
|
+
setTrack: (value) => {
|
|
64
|
+
tagWrapper.setTrack(value);
|
|
65
|
+
return tag;
|
|
66
|
+
}
|
|
47
67
|
};
|
|
68
|
+
return tag;
|
|
48
69
|
}
|
|
49
70
|
audioProperties() {
|
|
50
71
|
if (!this.cachedAudioProperties) {
|
|
@@ -115,7 +136,6 @@ class BaseAudioFileImpl {
|
|
|
115
136
|
this.fileHandle.destroy();
|
|
116
137
|
}
|
|
117
138
|
this.fileHandle = null;
|
|
118
|
-
this.cachedTag = null;
|
|
119
139
|
this.cachedAudioProperties = null;
|
|
120
140
|
}
|
|
121
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-file-impl.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAIjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,qBAAsB,YAAW,SAAS;gBAEzE,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,GAAG,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,cAAc,EAC/B,iBAAiB,GAAE,OAAe,EAClC,kBAAkB,CAAC,EAAE,WAAW;IAYlC,IAAI,IAAI,OAAO;
|
|
1
|
+
{"version":3,"file":"audio-file-impl.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAIjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,qBAAsB,YAAW,SAAS;gBAEzE,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,GAAG,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,cAAc,EAC/B,iBAAiB,GAAE,OAAe,EAClC,kBAAkB,CAAC,EAAE,WAAW;IAYlC,IAAI,IAAI,OAAO;IAWf,aAAa,IAAI,UAAU;IAKrB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqD9C,WAAW,IAAI,OAAO,EAAE;IAexB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAStC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IASlC,cAAc,IAAI,IAAI;IAItB,UAAU,IAAI,MAAM,EAAE;IAUtB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAQnC,SAAS,IAAI,MAAM,GAAG,SAAS;IAK/B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;CAGhD"}
|
|
@@ -19,7 +19,6 @@ class AudioFileImpl extends ExtendedAudioFileImpl {
|
|
|
19
19
|
"Cannot save partially loaded file directly. Use saveToFile() instead, which will automatically load the full file."
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
|
-
this.cachedTag = null;
|
|
23
22
|
this.cachedAudioProperties = null;
|
|
24
23
|
return this.fileHandle.save();
|
|
25
24
|
}
|
|
@@ -19,18 +19,18 @@ import type { Tag as BasicTag } from "../types.ts";
|
|
|
19
19
|
*/
|
|
20
20
|
export interface MutableTag extends BasicTag {
|
|
21
21
|
/** Set the track title */
|
|
22
|
-
setTitle(value: string):
|
|
22
|
+
setTitle(value: string): MutableTag;
|
|
23
23
|
/** Set the artist name */
|
|
24
|
-
setArtist(value: string):
|
|
24
|
+
setArtist(value: string): MutableTag;
|
|
25
25
|
/** Set the album name */
|
|
26
|
-
setAlbum(value: string):
|
|
26
|
+
setAlbum(value: string): MutableTag;
|
|
27
27
|
/** Set the comment */
|
|
28
|
-
setComment(value: string):
|
|
28
|
+
setComment(value: string): MutableTag;
|
|
29
29
|
/** Set the genre */
|
|
30
|
-
setGenre(value: string):
|
|
30
|
+
setGenre(value: string): MutableTag;
|
|
31
31
|
/** Set the release year */
|
|
32
|
-
setYear(value: number):
|
|
32
|
+
setYear(value: number): MutableTag;
|
|
33
33
|
/** Set the track number */
|
|
34
|
-
setTrack(value: number):
|
|
34
|
+
setTrack(value: number): MutableTag;
|
|
35
35
|
}
|
|
36
36
|
//# sourceMappingURL=mutable-tag.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutable-tag.d.ts","sourceRoot":"","sources":["../../../src/taglib/mutable-tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,UAAW,SAAQ,QAAQ;IAC1C,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"mutable-tag.d.ts","sourceRoot":"","sources":["../../../src/taglib/mutable-tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,UAAW,SAAQ,QAAQ;IAC1C,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACpC,0BAA0B;IAC1B,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACrC,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACpC,sBAAsB;IACtB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACtC,oBAAoB;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACpC,2BAA2B;IAC3B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACnC,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC"}
|
|
@@ -33,6 +33,8 @@ export declare class TagLib {
|
|
|
33
33
|
setWorkerPool(pool: TagLibWorkerPool | null): void;
|
|
34
34
|
getWorkerPool(): TagLibWorkerPool | undefined;
|
|
35
35
|
open(input: string | ArrayBuffer | Uint8Array | File, options?: OpenOptions): Promise<AudioFile>;
|
|
36
|
+
edit(input: string, fn: (file: AudioFile) => void | Promise<void>): Promise<void>;
|
|
37
|
+
edit(input: Uint8Array | ArrayBuffer | File, fn: (file: AudioFile) => void | Promise<void>): Promise<Uint8Array>;
|
|
36
38
|
updateFile(path: string, tags: Partial<BasicTag>): Promise<void>;
|
|
37
39
|
copyWithTags(sourcePath: string, destPath: string, tags: Partial<BasicTag>): Promise<void>;
|
|
38
40
|
batchOperations(file: string | Uint8Array, operations: BatchOperation[]): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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I,EAAE,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC;IACV,IAAI,CACR,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,EACtC,EAAE,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC5C,OAAO,CAAC,UAAU,CAAC;IAmBhB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUhE,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GACtB,OAAO,CAAC,IAAI,CAAC;IAUV,eAAe,CACnB,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,UAAU,EAAE,cAAc,EAAE,GAC3B,OAAO,CAAC,GAAG,CAAC;IAST,YAAY,CAAC,CAAC,EAClB,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,UAAU,GAAG,gBAAgB,GACvC,OAAO,CAAC,CAAC,EAAE,CAAC;IAiBf,OAAO,IAAI,MAAM;CAGlB;AAaD;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE"}
|
|
@@ -81,6 +81,20 @@ class TagLib {
|
|
|
81
81
|
opts
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
|
+
async edit(input, fn) {
|
|
85
|
+
const file = await this.open(input);
|
|
86
|
+
try {
|
|
87
|
+
await fn(file);
|
|
88
|
+
if (typeof input === "string") {
|
|
89
|
+
await file.saveToFile();
|
|
90
|
+
} else {
|
|
91
|
+
file.save();
|
|
92
|
+
return file.getFileBuffer();
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
file.dispose();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
84
98
|
async updateFile(path, tags) {
|
|
85
99
|
const file = await this.open(path);
|
|
86
100
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
applyCoverArt,
|
|
2
3
|
applyTags,
|
|
3
4
|
readProperties,
|
|
4
5
|
setBufferMode,
|
|
5
|
-
setCoverArt,
|
|
6
6
|
updateTags
|
|
7
7
|
} from "../simple.js";
|
|
8
8
|
const workerSelf = self;
|
|
@@ -161,7 +161,7 @@ workerSelf.onmessage = async (event) => {
|
|
|
161
161
|
break;
|
|
162
162
|
}
|
|
163
163
|
case "setCoverArt": {
|
|
164
|
-
const buffer = await
|
|
164
|
+
const buffer = await applyCoverArt(
|
|
165
165
|
params.file,
|
|
166
166
|
params.coverArt,
|
|
167
167
|
params.mimeType
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taglib-wasm",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
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",
|