taglib-wasm 1.0.8 → 1.1.1
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/dist/index.browser.js +87 -8
- package/dist/simple.browser.js +87 -8
- package/dist/src/deno-compile.js +1 -1
- package/dist/src/runtime/module-loader.d.ts.map +1 -1
- package/dist/src/runtime/module-loader.js +2 -3
- package/dist/src/runtime/unified-loader/module-loading.d.ts.map +1 -1
- package/dist/src/runtime/unified-loader/module-loading.js +26 -19
- package/dist/src/runtime/unified-loader/module-selection.d.ts.map +1 -1
- package/dist/src/runtime/unified-loader/module-selection.js +0 -1
- package/dist/src/runtime/unified-loader/types.d.ts +1 -3
- package/dist/src/runtime/unified-loader/types.d.ts.map +1 -1
- package/dist/src/runtime/wasi-adapter/adapter.d.ts +1 -1
- package/dist/src/runtime/wasi-adapter/adapter.js +1 -1
- package/dist/src/runtime/wasi-adapter/file-handle.d.ts +3 -2
- package/dist/src/runtime/wasi-adapter/file-handle.d.ts.map +1 -1
- package/dist/src/runtime/wasi-adapter/file-handle.js +27 -11
- package/dist/src/runtime/wasi-adapter/wasm-io.d.ts +3 -1
- package/dist/src/runtime/wasi-adapter/wasm-io.d.ts.map +1 -1
- package/dist/src/runtime/wasi-adapter/wasm-io.js +66 -1
- package/dist/src/runtime/wasi-host-loader.d.ts +1 -1
- package/dist/src/runtime/wasi-host-loader.js +1 -1
- package/dist/src/runtime/wasmer-sdk-loader/types.d.ts +1 -24
- package/dist/src/runtime/wasmer-sdk-loader/types.d.ts.map +1 -1
- package/dist/src/runtime/wasmer-sdk-loader/types.js +1 -19
- package/dist/src/taglib/audio-file-impl.d.ts +1 -0
- package/dist/src/taglib/audio-file-impl.d.ts.map +1 -1
- package/dist/src/taglib/audio-file-impl.js +37 -6
- package/dist/src/taglib/taglib-class.d.ts.map +1 -1
- package/dist/src/taglib/taglib-class.js +52 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/wasm.d.ts +3 -0
- package/dist/src/wasm.d.ts.map +1 -1
- package/dist/taglib_wasi.wasm +0 -0
- package/package.json +2 -2
- package/dist/src/runtime/wasmer-sdk-loader/high-level-api.d.ts +0 -10
- package/dist/src/runtime/wasmer-sdk-loader/high-level-api.d.ts.map +0 -1
- package/dist/src/runtime/wasmer-sdk-loader/high-level-api.js +0 -83
- package/dist/src/runtime/wasmer-sdk-loader/index.d.ts +0 -6
- package/dist/src/runtime/wasmer-sdk-loader/index.d.ts.map +0 -1
- package/dist/src/runtime/wasmer-sdk-loader/index.js +0 -17
- package/dist/src/runtime/wasmer-sdk-loader/initialization.d.ts +0 -16
- package/dist/src/runtime/wasmer-sdk-loader/initialization.d.ts.map +0 -1
- package/dist/src/runtime/wasmer-sdk-loader/initialization.js +0 -55
- package/dist/src/runtime/wasmer-sdk-loader/loader.d.ts +0 -9
- package/dist/src/runtime/wasmer-sdk-loader/loader.d.ts.map +0 -1
- package/dist/src/runtime/wasmer-sdk-loader/loader.js +0 -47
- package/dist/src/runtime/wasmer-sdk-loader/module-creation.d.ts +0 -9
- package/dist/src/runtime/wasmer-sdk-loader/module-creation.d.ts.map +0 -1
- package/dist/src/runtime/wasmer-sdk-loader/module-creation.js +0 -71
- package/dist/src/runtime/wasmer-sdk-loader/wasi-stubs.d.ts +0 -16
- package/dist/src/runtime/wasmer-sdk-loader/wasi-stubs.d.ts.map +0 -1
- package/dist/src/runtime/wasmer-sdk-loader/wasi-stubs.js +0 -64
package/dist/index.browser.js
CHANGED
|
@@ -1376,7 +1376,19 @@ var init_audio_file_base = __esm({
|
|
|
1376
1376
|
});
|
|
1377
1377
|
|
|
1378
1378
|
// src/taglib/audio-file-impl.ts
|
|
1379
|
-
|
|
1379
|
+
function readFileSync(path) {
|
|
1380
|
+
if (typeof Deno !== "undefined") return Deno.readFileSync(path);
|
|
1381
|
+
if (_nodeFs === void 0) {
|
|
1382
|
+
try {
|
|
1383
|
+
_nodeFs = new Function("return require('node:fs')")();
|
|
1384
|
+
} catch {
|
|
1385
|
+
_nodeFs = null;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
if (_nodeFs) return new Uint8Array(_nodeFs.readFileSync(path));
|
|
1389
|
+
return new Uint8Array(0);
|
|
1390
|
+
}
|
|
1391
|
+
var _nodeFs, AudioFileImpl;
|
|
1380
1392
|
var init_audio_file_impl = __esm({
|
|
1381
1393
|
"src/taglib/audio-file-impl.ts"() {
|
|
1382
1394
|
"use strict";
|
|
@@ -1395,6 +1407,7 @@ var init_audio_file_impl = __esm({
|
|
|
1395
1407
|
isPartiallyLoaded,
|
|
1396
1408
|
partialLoadOptions
|
|
1397
1409
|
);
|
|
1410
|
+
__publicField(this, "pathModeBuffer", null);
|
|
1398
1411
|
}
|
|
1399
1412
|
save() {
|
|
1400
1413
|
if (this.isPartiallyLoaded && this.originalSource) {
|
|
@@ -1408,7 +1421,17 @@ var init_audio_file_impl = __esm({
|
|
|
1408
1421
|
}
|
|
1409
1422
|
getFileBuffer() {
|
|
1410
1423
|
const buffer = this.handle.getBuffer();
|
|
1411
|
-
|
|
1424
|
+
if (buffer.length > 0) return buffer;
|
|
1425
|
+
if (this.pathModeBuffer) return this.pathModeBuffer;
|
|
1426
|
+
if (this.sourcePath) {
|
|
1427
|
+
try {
|
|
1428
|
+
this.pathModeBuffer = readFileSync(this.sourcePath);
|
|
1429
|
+
return this.pathModeBuffer;
|
|
1430
|
+
} catch {
|
|
1431
|
+
return new Uint8Array(0);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
return new Uint8Array(0);
|
|
1412
1435
|
}
|
|
1413
1436
|
async saveToFile(path) {
|
|
1414
1437
|
const targetPath = path ?? this.sourcePath;
|
|
@@ -1419,14 +1442,15 @@ var init_audio_file_impl = __esm({
|
|
|
1419
1442
|
);
|
|
1420
1443
|
}
|
|
1421
1444
|
if (this.isPartiallyLoaded && this.originalSource) {
|
|
1422
|
-
const fullData = await readFileData(this.originalSource);
|
|
1423
1445
|
const fullFileHandle = this.module.createFileHandle();
|
|
1424
1446
|
try {
|
|
1425
|
-
const success =
|
|
1447
|
+
const success = await (async () => {
|
|
1448
|
+
const data = await readFileData(this.originalSource);
|
|
1449
|
+
return fullFileHandle.loadFromBuffer(data);
|
|
1450
|
+
})();
|
|
1426
1451
|
if (!success) {
|
|
1427
1452
|
throw new InvalidFormatError(
|
|
1428
|
-
"Failed to load full audio file for saving"
|
|
1429
|
-
fullData.byteLength
|
|
1453
|
+
"Failed to load full audio file for saving"
|
|
1430
1454
|
);
|
|
1431
1455
|
}
|
|
1432
1456
|
const partialTag = this.handle.getTag();
|
|
@@ -1462,7 +1486,10 @@ var init_audio_file_impl = __esm({
|
|
|
1462
1486
|
"Failed to save changes to in-memory buffer"
|
|
1463
1487
|
);
|
|
1464
1488
|
}
|
|
1465
|
-
|
|
1489
|
+
const buffer = this.handle.getBuffer();
|
|
1490
|
+
if (buffer.length > 0) {
|
|
1491
|
+
await writeFileData(targetPath, buffer);
|
|
1492
|
+
}
|
|
1466
1493
|
}
|
|
1467
1494
|
}
|
|
1468
1495
|
getPictures() {
|
|
@@ -1666,7 +1693,7 @@ var VERSION;
|
|
|
1666
1693
|
var init_version = __esm({
|
|
1667
1694
|
"src/version.ts"() {
|
|
1668
1695
|
"use strict";
|
|
1669
|
-
VERSION = "1.
|
|
1696
|
+
VERSION = "1.1.1";
|
|
1670
1697
|
}
|
|
1671
1698
|
});
|
|
1672
1699
|
|
|
@@ -1716,6 +1743,30 @@ var init_module_loader_browser = __esm({
|
|
|
1716
1743
|
});
|
|
1717
1744
|
|
|
1718
1745
|
// src/taglib/taglib-class.ts
|
|
1746
|
+
function toWasiPath(osPath) {
|
|
1747
|
+
if (osPath.startsWith("\\\\") || osPath.startsWith("//")) {
|
|
1748
|
+
throw new FileOperationError(
|
|
1749
|
+
"read",
|
|
1750
|
+
`UNC paths are not supported. Path: ${osPath}`
|
|
1751
|
+
);
|
|
1752
|
+
}
|
|
1753
|
+
let p = osPath;
|
|
1754
|
+
if (!p.startsWith("/") && !/^[A-Za-z]:/.test(p)) {
|
|
1755
|
+
const g = globalThis;
|
|
1756
|
+
const cwd = typeof Deno !== "undefined" ? Deno.cwd() : g.process?.cwd?.();
|
|
1757
|
+
if (cwd) {
|
|
1758
|
+
p = cwd.replace(/[/\\]+$/, "") + "/" + p;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
p = p.replaceAll("\\", "/");
|
|
1762
|
+
const driveMatch = p.match(/^([A-Za-z]):\//);
|
|
1763
|
+
if (driveMatch) {
|
|
1764
|
+
p = `/${driveMatch[1].toUpperCase()}${p.slice(2)}`;
|
|
1765
|
+
}
|
|
1766
|
+
p = p.replace(/\/\.\//g, "/").replace(/\/+/g, "/");
|
|
1767
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
1768
|
+
return p;
|
|
1769
|
+
}
|
|
1719
1770
|
async function createTagLib(module) {
|
|
1720
1771
|
return new TagLib(module);
|
|
1721
1772
|
}
|
|
@@ -1728,6 +1779,7 @@ var init_taglib_class = __esm({
|
|
|
1728
1779
|
init_audio_file_impl();
|
|
1729
1780
|
init_load_audio_data();
|
|
1730
1781
|
init_tag_mapping();
|
|
1782
|
+
init_errors2();
|
|
1731
1783
|
init_version();
|
|
1732
1784
|
TagLib = class _TagLib {
|
|
1733
1785
|
constructor(module) {
|
|
@@ -1761,6 +1813,33 @@ var init_taglib_class = __esm({
|
|
|
1761
1813
|
}
|
|
1762
1814
|
const actualInput = isNamedAudioInput(input) ? input.data : input;
|
|
1763
1815
|
const sourcePath = typeof actualInput === "string" ? actualInput : void 0;
|
|
1816
|
+
if (typeof actualInput === "string" && this.module.isWasi) {
|
|
1817
|
+
const fileHandle2 = this.module.createFileHandle();
|
|
1818
|
+
try {
|
|
1819
|
+
const fh = fileHandle2;
|
|
1820
|
+
if (fh.loadFromPath) {
|
|
1821
|
+
const wasiPath = toWasiPath(actualInput);
|
|
1822
|
+
const success = fh.loadFromPath(wasiPath);
|
|
1823
|
+
if (!success) {
|
|
1824
|
+
throw new InvalidFormatError(
|
|
1825
|
+
`Failed to load audio file. Path: ${actualInput}`
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
return new AudioFileImpl(
|
|
1829
|
+
this.module,
|
|
1830
|
+
fileHandle2,
|
|
1831
|
+
sourcePath,
|
|
1832
|
+
actualInput,
|
|
1833
|
+
false
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
} catch (error) {
|
|
1837
|
+
if (typeof fileHandle2.destroy === "function") {
|
|
1838
|
+
fileHandle2.destroy();
|
|
1839
|
+
}
|
|
1840
|
+
throw error;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1764
1843
|
const opts = {
|
|
1765
1844
|
partial: true,
|
|
1766
1845
|
maxHeaderSize: 1024 * 1024,
|
package/dist/simple.browser.js
CHANGED
|
@@ -1364,7 +1364,19 @@ var init_audio_file_base = __esm({
|
|
|
1364
1364
|
});
|
|
1365
1365
|
|
|
1366
1366
|
// src/taglib/audio-file-impl.ts
|
|
1367
|
-
|
|
1367
|
+
function readFileSync(path) {
|
|
1368
|
+
if (typeof Deno !== "undefined") return Deno.readFileSync(path);
|
|
1369
|
+
if (_nodeFs === void 0) {
|
|
1370
|
+
try {
|
|
1371
|
+
_nodeFs = new Function("return require('node:fs')")();
|
|
1372
|
+
} catch {
|
|
1373
|
+
_nodeFs = null;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
if (_nodeFs) return new Uint8Array(_nodeFs.readFileSync(path));
|
|
1377
|
+
return new Uint8Array(0);
|
|
1378
|
+
}
|
|
1379
|
+
var _nodeFs, AudioFileImpl;
|
|
1368
1380
|
var init_audio_file_impl = __esm({
|
|
1369
1381
|
"src/taglib/audio-file-impl.ts"() {
|
|
1370
1382
|
"use strict";
|
|
@@ -1383,6 +1395,7 @@ var init_audio_file_impl = __esm({
|
|
|
1383
1395
|
isPartiallyLoaded,
|
|
1384
1396
|
partialLoadOptions
|
|
1385
1397
|
);
|
|
1398
|
+
__publicField(this, "pathModeBuffer", null);
|
|
1386
1399
|
}
|
|
1387
1400
|
save() {
|
|
1388
1401
|
if (this.isPartiallyLoaded && this.originalSource) {
|
|
@@ -1396,7 +1409,17 @@ var init_audio_file_impl = __esm({
|
|
|
1396
1409
|
}
|
|
1397
1410
|
getFileBuffer() {
|
|
1398
1411
|
const buffer = this.handle.getBuffer();
|
|
1399
|
-
|
|
1412
|
+
if (buffer.length > 0) return buffer;
|
|
1413
|
+
if (this.pathModeBuffer) return this.pathModeBuffer;
|
|
1414
|
+
if (this.sourcePath) {
|
|
1415
|
+
try {
|
|
1416
|
+
this.pathModeBuffer = readFileSync(this.sourcePath);
|
|
1417
|
+
return this.pathModeBuffer;
|
|
1418
|
+
} catch {
|
|
1419
|
+
return new Uint8Array(0);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
return new Uint8Array(0);
|
|
1400
1423
|
}
|
|
1401
1424
|
async saveToFile(path) {
|
|
1402
1425
|
const targetPath = path ?? this.sourcePath;
|
|
@@ -1407,14 +1430,15 @@ var init_audio_file_impl = __esm({
|
|
|
1407
1430
|
);
|
|
1408
1431
|
}
|
|
1409
1432
|
if (this.isPartiallyLoaded && this.originalSource) {
|
|
1410
|
-
const fullData = await readFileData(this.originalSource);
|
|
1411
1433
|
const fullFileHandle = this.module.createFileHandle();
|
|
1412
1434
|
try {
|
|
1413
|
-
const success =
|
|
1435
|
+
const success = await (async () => {
|
|
1436
|
+
const data = await readFileData(this.originalSource);
|
|
1437
|
+
return fullFileHandle.loadFromBuffer(data);
|
|
1438
|
+
})();
|
|
1414
1439
|
if (!success) {
|
|
1415
1440
|
throw new InvalidFormatError(
|
|
1416
|
-
"Failed to load full audio file for saving"
|
|
1417
|
-
fullData.byteLength
|
|
1441
|
+
"Failed to load full audio file for saving"
|
|
1418
1442
|
);
|
|
1419
1443
|
}
|
|
1420
1444
|
const partialTag = this.handle.getTag();
|
|
@@ -1450,7 +1474,10 @@ var init_audio_file_impl = __esm({
|
|
|
1450
1474
|
"Failed to save changes to in-memory buffer"
|
|
1451
1475
|
);
|
|
1452
1476
|
}
|
|
1453
|
-
|
|
1477
|
+
const buffer = this.handle.getBuffer();
|
|
1478
|
+
if (buffer.length > 0) {
|
|
1479
|
+
await writeFileData(targetPath, buffer);
|
|
1480
|
+
}
|
|
1454
1481
|
}
|
|
1455
1482
|
}
|
|
1456
1483
|
getPictures() {
|
|
@@ -1654,7 +1681,7 @@ var VERSION;
|
|
|
1654
1681
|
var init_version = __esm({
|
|
1655
1682
|
"src/version.ts"() {
|
|
1656
1683
|
"use strict";
|
|
1657
|
-
VERSION = "1.
|
|
1684
|
+
VERSION = "1.1.1";
|
|
1658
1685
|
}
|
|
1659
1686
|
});
|
|
1660
1687
|
|
|
@@ -1703,6 +1730,30 @@ var init_module_loader_browser = __esm({
|
|
|
1703
1730
|
});
|
|
1704
1731
|
|
|
1705
1732
|
// src/taglib/taglib-class.ts
|
|
1733
|
+
function toWasiPath(osPath) {
|
|
1734
|
+
if (osPath.startsWith("\\\\") || osPath.startsWith("//")) {
|
|
1735
|
+
throw new FileOperationError(
|
|
1736
|
+
"read",
|
|
1737
|
+
`UNC paths are not supported. Path: ${osPath}`
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
let p = osPath;
|
|
1741
|
+
if (!p.startsWith("/") && !/^[A-Za-z]:/.test(p)) {
|
|
1742
|
+
const g = globalThis;
|
|
1743
|
+
const cwd = typeof Deno !== "undefined" ? Deno.cwd() : g.process?.cwd?.();
|
|
1744
|
+
if (cwd) {
|
|
1745
|
+
p = cwd.replace(/[/\\]+$/, "") + "/" + p;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
p = p.replaceAll("\\", "/");
|
|
1749
|
+
const driveMatch = p.match(/^([A-Za-z]):\//);
|
|
1750
|
+
if (driveMatch) {
|
|
1751
|
+
p = `/${driveMatch[1].toUpperCase()}${p.slice(2)}`;
|
|
1752
|
+
}
|
|
1753
|
+
p = p.replace(/\/\.\//g, "/").replace(/\/+/g, "/");
|
|
1754
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
1755
|
+
return p;
|
|
1756
|
+
}
|
|
1706
1757
|
async function createTagLib(module) {
|
|
1707
1758
|
return new TagLib(module);
|
|
1708
1759
|
}
|
|
@@ -1715,6 +1766,7 @@ var init_taglib_class = __esm({
|
|
|
1715
1766
|
init_audio_file_impl();
|
|
1716
1767
|
init_load_audio_data();
|
|
1717
1768
|
init_tag_mapping();
|
|
1769
|
+
init_errors2();
|
|
1718
1770
|
init_version();
|
|
1719
1771
|
TagLib = class _TagLib {
|
|
1720
1772
|
constructor(module) {
|
|
@@ -1748,6 +1800,33 @@ var init_taglib_class = __esm({
|
|
|
1748
1800
|
}
|
|
1749
1801
|
const actualInput = isNamedAudioInput(input) ? input.data : input;
|
|
1750
1802
|
const sourcePath = typeof actualInput === "string" ? actualInput : void 0;
|
|
1803
|
+
if (typeof actualInput === "string" && this.module.isWasi) {
|
|
1804
|
+
const fileHandle2 = this.module.createFileHandle();
|
|
1805
|
+
try {
|
|
1806
|
+
const fh = fileHandle2;
|
|
1807
|
+
if (fh.loadFromPath) {
|
|
1808
|
+
const wasiPath = toWasiPath(actualInput);
|
|
1809
|
+
const success = fh.loadFromPath(wasiPath);
|
|
1810
|
+
if (!success) {
|
|
1811
|
+
throw new InvalidFormatError(
|
|
1812
|
+
`Failed to load audio file. Path: ${actualInput}`
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
return new AudioFileImpl(
|
|
1816
|
+
this.module,
|
|
1817
|
+
fileHandle2,
|
|
1818
|
+
sourcePath,
|
|
1819
|
+
actualInput,
|
|
1820
|
+
false
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
} catch (error) {
|
|
1824
|
+
if (typeof fileHandle2.destroy === "function") {
|
|
1825
|
+
fileHandle2.destroy();
|
|
1826
|
+
}
|
|
1827
|
+
throw error;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1751
1830
|
const opts = {
|
|
1752
1831
|
partial: true,
|
|
1753
1832
|
maxHeaderSize: 1024 * 1024,
|
package/dist/src/deno-compile.js
CHANGED
|
@@ -32,7 +32,7 @@ async function prepareWasmForEmbedding(outputPath = "./taglib-web.wasm") {
|
|
|
32
32
|
try {
|
|
33
33
|
const possiblePaths = [
|
|
34
34
|
new URL("../dist/taglib-web.wasm", import.meta.url),
|
|
35
|
-
new URL("../
|
|
35
|
+
new URL("../taglib-web.wasm", import.meta.url),
|
|
36
36
|
new URL(
|
|
37
37
|
"./node_modules/taglib-wasm/dist/taglib-web.wasm",
|
|
38
38
|
import.meta.url
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-loader.d.ts","sourceRoot":"","sources":["../../../src/runtime/module-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"module-loader.d.ts","sourceRoot":"","sources":["../../../src/runtime/module-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAkDvB"}
|
|
@@ -34,8 +34,7 @@ async function loadTagLibModule(options) {
|
|
|
34
34
|
wasmBinary: options?.wasmBinary,
|
|
35
35
|
wasmUrl: options?.wasmUrl,
|
|
36
36
|
forceWasmType: options?.forceWasmType,
|
|
37
|
-
debug: false
|
|
38
|
-
useInlineWasm: false
|
|
37
|
+
debug: false
|
|
39
38
|
});
|
|
40
39
|
} catch (error) {
|
|
41
40
|
console.warn(
|
|
@@ -71,7 +70,7 @@ async function loadBufferModeTagLibModule(options) {
|
|
|
71
70
|
return path;
|
|
72
71
|
};
|
|
73
72
|
} else if (!options?.wasmBinary) {
|
|
74
|
-
const wasmUrl = new URL("../../
|
|
73
|
+
const wasmUrl = new URL("../../taglib-web.wasm", import.meta.url);
|
|
75
74
|
moduleConfig.locateFile = (path) => path.endsWith(".wasm") ? wasmUrl.href : path;
|
|
76
75
|
}
|
|
77
76
|
const module = await createTagLibModule(moduleConfig);
|
|
@@ -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;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
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;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA0CzE,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAS3B"}
|
|
@@ -2,6 +2,27 @@ import { supportsExnref } from "../detector.js";
|
|
|
2
2
|
import { ModuleLoadError } from "./types.js";
|
|
3
3
|
import { errorMessage } from "../../errors/classes.js";
|
|
4
4
|
import { fileUrlToPath } from "../../utils/path.js";
|
|
5
|
+
function isWindows() {
|
|
6
|
+
return typeof Deno !== "undefined" ? Deno.build.os === "windows" : globalThis.process ? globalThis.process.platform === "win32" : false;
|
|
7
|
+
}
|
|
8
|
+
function getPreopens() {
|
|
9
|
+
if (!isWindows()) return { "/": "/" };
|
|
10
|
+
const preopens = {};
|
|
11
|
+
for (const letter of "CDEFGHIJKLMNOPQRSTUVWXYZAB") {
|
|
12
|
+
const root = `${letter}:\\`;
|
|
13
|
+
try {
|
|
14
|
+
if (typeof Deno !== "undefined") {
|
|
15
|
+
Deno.statSync(root);
|
|
16
|
+
} else {
|
|
17
|
+
const fs = new Function("return require('node:fs')")();
|
|
18
|
+
fs.statSync(root);
|
|
19
|
+
}
|
|
20
|
+
preopens[`/${letter}`] = root;
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return Object.keys(preopens).length > 0 ? preopens : { "/C": "C:\\" };
|
|
25
|
+
}
|
|
5
26
|
function resolveWasmPath(relativePath) {
|
|
6
27
|
const url = new URL(relativePath, import.meta.url);
|
|
7
28
|
return url.protocol === "file:" ? fileUrlToPath(url) : url.href;
|
|
@@ -17,11 +38,12 @@ async function loadModule(wasmType, runtime, options) {
|
|
|
17
38
|
}
|
|
18
39
|
}
|
|
19
40
|
async function loadWasiModuleWithFallback(runtime, options) {
|
|
20
|
-
const defaultWasmPath = resolveWasmPath("../../../
|
|
41
|
+
const defaultWasmPath = resolveWasmPath("../../../taglib_wasi.wasm");
|
|
21
42
|
try {
|
|
22
43
|
const { loadWasiHost } = await import("../wasi-host-loader.js");
|
|
23
44
|
const wasiModule = await loadWasiHost({
|
|
24
|
-
wasmPath: options.wasmUrl || defaultWasmPath
|
|
45
|
+
wasmPath: options.wasmUrl || defaultWasmPath,
|
|
46
|
+
preopens: getPreopens()
|
|
25
47
|
});
|
|
26
48
|
return { module: wasiModule, actualWasmType: "wasi" };
|
|
27
49
|
} catch (hostError) {
|
|
@@ -35,22 +57,8 @@ async function loadWasiModuleWithFallback(runtime, options) {
|
|
|
35
57
|
console.warn(`[UnifiedLoader] WASI host failed:`, hostError);
|
|
36
58
|
}
|
|
37
59
|
}
|
|
38
|
-
try {
|
|
39
|
-
const { initializeWasmer, loadWasmerWasi } = await import("../wasmer-sdk-loader/index.js");
|
|
40
|
-
await initializeWasmer(options.useInlineWasm);
|
|
41
|
-
const wasiModule = await loadWasmerWasi({
|
|
42
|
-
wasmPath: options.wasmUrl || defaultWasmPath,
|
|
43
|
-
useInlineWasm: options.useInlineWasm,
|
|
44
|
-
debug: options.debug
|
|
45
|
-
});
|
|
46
|
-
return { module: wasiModule, actualWasmType: "wasi" };
|
|
47
|
-
} catch (sdkError) {
|
|
48
|
-
if (options.debug) {
|
|
49
|
-
console.warn(`[UnifiedLoader] Wasmer SDK failed:`, sdkError);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
60
|
if (options.debug) {
|
|
53
|
-
console.warn(`[UnifiedLoader]
|
|
61
|
+
console.warn(`[UnifiedLoader] WASI loader failed, using Emscripten`);
|
|
54
62
|
}
|
|
55
63
|
return {
|
|
56
64
|
module: await loadEmscriptenModule(options),
|
|
@@ -83,8 +91,7 @@ async function loadEmscriptenModule(options) {
|
|
|
83
91
|
return path.endsWith(".wasm") ? options.wasmUrl : path;
|
|
84
92
|
};
|
|
85
93
|
} else if (!options.wasmBinary) {
|
|
86
|
-
const wasmUrl = new URL(
|
|
87
|
-
"../../../build/taglib-web.wasm",
|
|
94
|
+
const wasmUrl = new URL("../../../taglib-web.wasm",
|
|
88
95
|
import.meta.url
|
|
89
96
|
);
|
|
90
97
|
moduleConfig.locateFile = (path) => path.endsWith(".wasm") ? wasmUrl.href : path;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-selection.d.ts","sourceRoot":"","sources":["../../../../src/runtime/unified-loader/module-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,MAAM,GAAG,YAAY,CAcvB;AAED,wBAAgB,eAAe,IAAI,OAAO,CAGzC;AAED,wBAAgB,oBAAoB,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"module-selection.d.ts","sourceRoot":"","sources":["../../../../src/runtime/unified-loader/module-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,MAAM,GAAG,YAAY,CAcvB;AAED,wBAAgB,eAAe,IAAI,OAAO,CAGzC;AAED,wBAAgB,oBAAoB,IAAI,oBAAoB,CAoB3D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RuntimeDetectionResult } from "../detector.js";
|
|
2
|
-
import type { WasiModule } from "../wasmer-sdk-loader/
|
|
2
|
+
import type { WasiModule } from "../wasmer-sdk-loader/types.js";
|
|
3
3
|
import type { TagLibModule } from "../../wasm.js";
|
|
4
4
|
import { TagLibError } from "../../errors/base.js";
|
|
5
5
|
export declare class UnifiedLoaderError extends TagLibError {
|
|
@@ -20,8 +20,6 @@ export interface UnifiedLoaderOptions {
|
|
|
20
20
|
wasmUrl?: string;
|
|
21
21
|
/** Enable debug output */
|
|
22
22
|
debug?: boolean;
|
|
23
|
-
/** Use inline WASM for bundling */
|
|
24
|
-
useInlineWasm?: boolean;
|
|
25
23
|
}
|
|
26
24
|
export interface UnifiedTagLibModule extends TagLibModule {
|
|
27
25
|
/** Runtime environment info */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/runtime/unified-loader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAM7C;AAED,qBAAa,eAAgB,SAAQ,WAAW;aAG5B,QAAQ,EAAE,MAAM,GAAG,YAAY;gBAD/C,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/C,KAAK,CAAC,EAAE,OAAO;CAOlB;AAED,MAAM,WAAW,oBAAoB;IACnC,+BAA+B;IAC/B,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACtC,0CAA0C;IAC1C,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,sCAAsC;IACtC,UAAU,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;IACtC,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/runtime/unified-loader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAM7C;AAED,qBAAa,eAAgB,SAAQ,WAAW;aAG5B,QAAQ,EAAE,MAAM,GAAG,YAAY;gBAD/C,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/C,KAAK,CAAC,EAAE,OAAO;CAOlB;AAED,MAAM,WAAW,oBAAoB;IACnC,+BAA+B;IAC/B,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACtC,0CAA0C;IAC1C,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,sCAAsC;IACtC,UAAU,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;IACtC,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,+BAA+B;IAC/B,OAAO,EAAE,sBAAsB,CAAC;IAChC,wCAAwC;IACxC,MAAM,EAAE,OAAO,CAAC;IAChB,8CAA8C;IAC9C,YAAY,EAAE,OAAO,CAAC;IACtB,8BAA8B;IAC9B,qBAAqB,CAAC,EAAE,MAAM,kBAAkB,CAAC;CAClD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,YAAY,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,YAAY,GAAG,UAAU,CAAC;IAClC,cAAc,EAAE,MAAM,GAAG,YAAY,CAAC;CACvC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* providing Emscripten-compatible memory access and string operations.
|
|
6
6
|
*/
|
|
7
7
|
import type { FileHandle, TagLibModule } from "../../wasm.js";
|
|
8
|
-
import type { WasiModule } from "../wasmer-sdk-loader/
|
|
8
|
+
import type { WasiModule } from "../wasmer-sdk-loader/types.js";
|
|
9
9
|
export declare class WasiToTagLibAdapter implements TagLibModule {
|
|
10
10
|
private readonly wasi;
|
|
11
11
|
private readonly heap;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (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
|
-
import { WasmerExecutionError } from "../wasmer-sdk-loader/
|
|
4
|
+
import { WasmerExecutionError } from "../wasmer-sdk-loader/types.js";
|
|
5
5
|
import { MemoryError } from "../../errors/classes.js";
|
|
6
6
|
import { WasiFileHandle } from "./file-handle.js";
|
|
7
7
|
class WasiToTagLibAdapter {
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
* @fileoverview WASI-based FileHandle implementation
|
|
3
3
|
*/
|
|
4
4
|
import type { AudioPropertiesWrapper, FileHandle, RawPicture, TagWrapper } from "../../wasm.js";
|
|
5
|
-
import type { WasiModule } from "../wasmer-sdk-loader/
|
|
5
|
+
import type { WasiModule } from "../wasmer-sdk-loader/types.js";
|
|
6
6
|
export declare class WasiFileHandle implements FileHandle {
|
|
7
7
|
private readonly wasi;
|
|
8
8
|
private fileData;
|
|
9
|
+
private filePath;
|
|
9
10
|
private tagData;
|
|
10
11
|
private destroyed;
|
|
11
12
|
constructor(wasiModule: WasiModule);
|
|
12
13
|
private checkNotDestroyed;
|
|
13
14
|
loadFromBuffer(buffer: Uint8Array): boolean;
|
|
14
|
-
loadFromPath(
|
|
15
|
+
loadFromPath(path: string): boolean;
|
|
15
16
|
isValid(): boolean;
|
|
16
17
|
save(): boolean;
|
|
17
18
|
getTag(): TagWrapper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-handle.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/file-handle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"file-handle.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/file-handle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAgDhE,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,SAAS,CAAS;gBAEd,UAAU,EAAE,UAAU;IAIlC,OAAO,CAAC,iBAAiB;IAQzB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO;IAW3C,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAWnC,OAAO,IAAI,OAAO;IAMlB,IAAI,IAAI,OAAO;IAqBf,MAAM,IAAI,UAAU;IASpB,OAAO,CAAC,gBAAgB;IAsCxB,kBAAkB,IAAI,sBAAsB,GAAG,IAAI;IAqBnD,SAAS,IAAI,MAAM;IA2DnB,OAAO,CAAC,cAAc;IAiBtB,SAAS,IAAI,UAAU;IAKvB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAuBzC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI;IAgBpD,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAOhC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAc7C,KAAK,IAAI,OAAO;IAehB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAK/B,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAK5C,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAShC,WAAW,IAAI,UAAU,EAAE;IAK3B,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI;IAKzC,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAOrC,cAAc,IAAI,IAAI;IAKtB,UAAU,IAAI;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE;IAOlE,UAAU,CACR,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,GAC9D,IAAI;IAaP,OAAO,IAAI,IAAI;CAKhB"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (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
|
-
import { WasmerExecutionError } from "../wasmer-sdk-loader/
|
|
4
|
+
import { WasmerExecutionError } from "../wasmer-sdk-loader/types.js";
|
|
5
5
|
import { decodeTagData } from "../../msgpack/decoder.js";
|
|
6
6
|
import { fromTagLibKey, toTagLibKey } from "../../constants/properties.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
readTagsFromWasm,
|
|
9
|
+
readTagsFromWasmPath,
|
|
10
|
+
writeTagsToWasm,
|
|
11
|
+
writeTagsToWasmPath
|
|
12
|
+
} from "./wasm-io.js";
|
|
8
13
|
const AUDIO_KEYS = /* @__PURE__ */ new Set([
|
|
9
14
|
"bitrate",
|
|
10
15
|
"bitsPerSample",
|
|
@@ -42,6 +47,7 @@ class WasiFileHandle {
|
|
|
42
47
|
constructor(wasiModule) {
|
|
43
48
|
__publicField(this, "wasi");
|
|
44
49
|
__publicField(this, "fileData", null);
|
|
50
|
+
__publicField(this, "filePath", null);
|
|
45
51
|
__publicField(this, "tagData", null);
|
|
46
52
|
__publicField(this, "destroyed", false);
|
|
47
53
|
this.wasi = wasiModule;
|
|
@@ -60,21 +66,28 @@ class WasiFileHandle {
|
|
|
60
66
|
this.tagData = decodeTagData(msgpackData);
|
|
61
67
|
return true;
|
|
62
68
|
}
|
|
63
|
-
loadFromPath(
|
|
69
|
+
loadFromPath(path) {
|
|
64
70
|
this.checkNotDestroyed();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
71
|
+
this.filePath = path;
|
|
72
|
+
const msgpackData = readTagsFromWasmPath(this.wasi, path);
|
|
73
|
+
this.tagData = decodeTagData(msgpackData);
|
|
74
|
+
return true;
|
|
68
75
|
}
|
|
69
76
|
isValid() {
|
|
70
77
|
this.checkNotDestroyed();
|
|
71
|
-
return this.fileData !== null && this.fileData.length > 0;
|
|
78
|
+
return this.fileData !== null && this.fileData.length > 0 || this.filePath !== null && this.tagData !== null;
|
|
72
79
|
}
|
|
73
80
|
save() {
|
|
74
81
|
this.checkNotDestroyed();
|
|
75
|
-
if (!this.
|
|
76
|
-
|
|
82
|
+
if (!this.tagData) return false;
|
|
83
|
+
if (this.filePath) {
|
|
84
|
+
return writeTagsToWasmPath(
|
|
85
|
+
this.wasi,
|
|
86
|
+
this.filePath,
|
|
87
|
+
this.tagData
|
|
88
|
+
);
|
|
77
89
|
}
|
|
90
|
+
if (!this.fileData) return false;
|
|
78
91
|
const result = writeTagsToWasm(this.wasi, this.fileData, this.tagData);
|
|
79
92
|
if (result) {
|
|
80
93
|
this.fileData = result;
|
|
@@ -147,13 +160,13 @@ class WasiFileHandle {
|
|
|
147
160
|
}
|
|
148
161
|
getFormat() {
|
|
149
162
|
this.checkNotDestroyed();
|
|
150
|
-
if (!this.fileData || this.fileData.length < 8) return "unknown";
|
|
151
163
|
const container = this.tagData?.containerFormat;
|
|
152
164
|
if (container) {
|
|
153
165
|
const codec = this.tagData?.codec;
|
|
154
166
|
if (container === "OGG" && codec === "Opus") return "OPUS";
|
|
155
167
|
if (CONTAINER_TO_FORMAT[container]) return CONTAINER_TO_FORMAT[container];
|
|
156
168
|
}
|
|
169
|
+
if (!this.fileData || this.fileData.length < 8) return "unknown";
|
|
157
170
|
const magic = this.fileData.slice(0, 4);
|
|
158
171
|
if (magic[0] === 255 && (magic[1] & 224) === 224) return "MP3";
|
|
159
172
|
if (magic[0] === 73 && magic[1] === 68 && magic[2] === 51) {
|
|
@@ -241,7 +254,10 @@ class WasiFileHandle {
|
|
|
241
254
|
}
|
|
242
255
|
isMP4() {
|
|
243
256
|
this.checkNotDestroyed();
|
|
244
|
-
if (!this.fileData
|
|
257
|
+
if (!this.fileData) {
|
|
258
|
+
return this.tagData?.containerFormat === "MP4";
|
|
259
|
+
}
|
|
260
|
+
if (this.fileData.length < 8) return false;
|
|
245
261
|
const magic = this.fileData.slice(4, 8);
|
|
246
262
|
return magic[0] === 102 && magic[1] === 116 && magic[2] === 121 && magic[3] === 112;
|
|
247
263
|
}
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* Pure functions that handle the low-level Wasm memory allocation
|
|
5
5
|
* and TagLib C API calls for reading and writing audio metadata.
|
|
6
6
|
*/
|
|
7
|
-
import type { WasiModule } from "../wasmer-sdk-loader/
|
|
7
|
+
import type { WasiModule } from "../wasmer-sdk-loader/types.js";
|
|
8
8
|
import type { ExtendedTag } from "../../types.js";
|
|
9
9
|
export declare function readTagsFromWasm(wasi: WasiModule, buffer: Uint8Array): Uint8Array;
|
|
10
|
+
export declare function readTagsFromWasmPath(wasi: WasiModule, path: string): Uint8Array;
|
|
11
|
+
export declare function writeTagsToWasmPath(wasi: WasiModule, path: string, tagData: ExtendedTag): boolean;
|
|
10
12
|
export declare function writeTagsToWasm(wasi: WasiModule, fileData: Uint8Array, tagData: ExtendedTag): Uint8Array | null;
|
|
11
13
|
//# sourceMappingURL=wasm-io.d.ts.map
|
|
@@ -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;AAQhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,UAAU,GACjB,UAAU,CAoCZ;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,WAAW,GACnB,UAAU,GAAG,IAAI,CA8BnB"}
|
|
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;AAQhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,UAAU,GACjB,UAAU,CAoCZ;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,GACX,UAAU,CA8BZ;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,GACnB,OAAO,CA2BT;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,WAAW,GACnB,UAAU,GAAG,IAAI,CA8BnB"}
|