taglib-wasm 0.3.13 → 0.3.15
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 +22 -35
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +117 -134
- package/dist/index.js.map +1 -0
- package/dist/src/constants.js +211 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.js +180 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/file-utils.d.ts +2 -2
- package/dist/src/file-utils.d.ts.map +1 -1
- package/dist/src/file-utils.js +394 -0
- package/dist/src/file-utils.js.map +1 -0
- package/dist/src/mod.d.ts +4 -4
- package/dist/src/mod.d.ts.map +1 -1
- package/dist/src/mod.js +7 -0
- package/dist/src/mod.js.map +1 -0
- package/dist/src/simple.d.ts +4 -4
- package/dist/src/simple.d.ts.map +1 -1
- package/dist/src/{simple.ts → simple.js} +193 -311
- package/dist/src/simple.js.map +1 -0
- package/dist/src/taglib.d.ts +3 -3
- package/dist/src/taglib.d.ts.map +1 -1
- package/dist/src/taglib.js +516 -0
- package/dist/src/taglib.js.map +1 -0
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +239 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/file.js +65 -0
- package/dist/src/utils/file.js.map +1 -0
- package/dist/src/utils/write.js +49 -0
- package/dist/src/utils/write.js.map +1 -0
- package/dist/src/wasm-workers.d.ts +1 -1
- package/dist/src/wasm-workers.d.ts.map +1 -1
- package/dist/src/wasm-workers.js +148 -0
- package/dist/src/wasm-workers.js.map +1 -0
- package/dist/src/wasm.js +6 -0
- package/dist/src/wasm.js.map +1 -0
- package/dist/src/web-utils.d.ts +2 -2
- package/dist/src/web-utils.d.ts.map +1 -1
- package/{src/web-utils.ts → dist/src/web-utils.js} +102 -184
- package/dist/src/web-utils.js.map +1 -0
- package/dist/src/workers.d.ts +2 -2
- package/dist/src/workers.d.ts.map +1 -1
- package/dist/src/workers.js +389 -0
- package/dist/src/workers.js.map +1 -0
- package/dist/taglib-wrapper.js +8 -2528
- package/package.json +7 -10
- package/dist/index.ts +0 -221
- package/dist/src/constants.ts +0 -227
- package/dist/src/errors.ts +0 -254
- package/dist/src/file-utils.ts +0 -483
- package/dist/src/file.js +0 -52
- package/dist/src/global.d.ts +0 -12
- package/dist/src/mod.ts +0 -19
- package/dist/src/taglib.ts +0 -961
- package/dist/src/types.ts +0 -538
- package/dist/src/utils/file.ts +0 -86
- package/dist/src/utils/write.ts +0 -66
- package/dist/src/wasm-workers.ts +0 -176
- package/dist/src/wasm.ts +0 -133
- package/dist/src/web-utils.ts +0 -347
- package/dist/src/workers.ts +0 -461
- package/dist/src/write.js +0 -33
- package/index.ts +0 -221
- package/lib/taglib/COPYING.LGPL +0 -502
- package/lib/taglib/COPYING.MPL +0 -470
- package/lib/taglib/README.md +0 -24
- package/src/constants.ts +0 -227
- package/src/errors.ts +0 -254
- package/src/file-utils.ts +0 -483
- package/src/global.d.ts +0 -12
- package/src/mod.ts +0 -19
- package/src/simple.ts +0 -667
- package/src/taglib.ts +0 -961
- package/src/types.ts +0 -538
- package/src/utils/file.ts +0 -86
- package/src/utils/write.ts +0 -66
- package/src/wasm-workers.ts +0 -176
- package/src/wasm.ts +0 -133
- package/src/workers.ts +0 -461
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TypeScript type definitions for taglib-wasm
|
|
3
|
+
*
|
|
4
|
+
* This module contains all the type definitions used throughout
|
|
5
|
+
* the taglib-wasm library, including metadata structures,
|
|
6
|
+
* audio properties, and format-specific mappings.
|
|
7
|
+
*
|
|
8
|
+
* @module taglib-wasm/types
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Complete metadata field mappings for all formats.
|
|
12
|
+
* This constant defines how each ExtendedTag field maps to
|
|
13
|
+
* format-specific metadata fields across different audio formats.
|
|
14
|
+
* Used for automatic tag mapping in format-agnostic operations.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Get the ID3v2 frame for the artist field
|
|
19
|
+
* const artistFrame = METADATA_MAPPINGS.artist.id3v2?.frame; // "TPE1"
|
|
20
|
+
*
|
|
21
|
+
* // Get the Vorbis comment field for album artist
|
|
22
|
+
* const vorbisField = METADATA_MAPPINGS.albumArtist.vorbis; // "ALBUMARTIST"
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const METADATA_MAPPINGS = {
|
|
26
|
+
// Basic fields (already handled by TagLib's standard API)
|
|
27
|
+
title: {
|
|
28
|
+
id3v2: { frame: "TIT2" },
|
|
29
|
+
vorbis: "TITLE",
|
|
30
|
+
mp4: "©nam",
|
|
31
|
+
wav: "INAM",
|
|
32
|
+
},
|
|
33
|
+
artist: {
|
|
34
|
+
id3v2: { frame: "TPE1" },
|
|
35
|
+
vorbis: "ARTIST",
|
|
36
|
+
mp4: "©ART",
|
|
37
|
+
wav: "IART",
|
|
38
|
+
},
|
|
39
|
+
album: {
|
|
40
|
+
id3v2: { frame: "TALB" },
|
|
41
|
+
vorbis: "ALBUM",
|
|
42
|
+
mp4: "©alb",
|
|
43
|
+
wav: "IPRD",
|
|
44
|
+
},
|
|
45
|
+
comment: {
|
|
46
|
+
id3v2: { frame: "COMM" },
|
|
47
|
+
vorbis: "COMMENT",
|
|
48
|
+
mp4: "©cmt",
|
|
49
|
+
wav: "ICMT",
|
|
50
|
+
},
|
|
51
|
+
genre: {
|
|
52
|
+
id3v2: { frame: "TCON" },
|
|
53
|
+
vorbis: "GENRE",
|
|
54
|
+
mp4: "©gen",
|
|
55
|
+
wav: "IGNR",
|
|
56
|
+
},
|
|
57
|
+
year: {
|
|
58
|
+
id3v2: { frame: "TDRC" },
|
|
59
|
+
vorbis: "DATE",
|
|
60
|
+
mp4: "©day",
|
|
61
|
+
wav: "ICRD",
|
|
62
|
+
},
|
|
63
|
+
track: {
|
|
64
|
+
id3v2: { frame: "TRCK" },
|
|
65
|
+
vorbis: "TRACKNUMBER",
|
|
66
|
+
mp4: "trkn",
|
|
67
|
+
wav: "ITRK",
|
|
68
|
+
},
|
|
69
|
+
// Advanced fields requiring format-specific handling
|
|
70
|
+
acoustidFingerprint: {
|
|
71
|
+
id3v2: { frame: "TXXX", description: "Acoustid Fingerprint" },
|
|
72
|
+
vorbis: "ACOUSTID_FINGERPRINT",
|
|
73
|
+
mp4: "----:com.apple.iTunes:Acoustid Fingerprint",
|
|
74
|
+
},
|
|
75
|
+
acoustidId: {
|
|
76
|
+
id3v2: { frame: "TXXX", description: "Acoustid Id" },
|
|
77
|
+
vorbis: "ACOUSTID_ID",
|
|
78
|
+
mp4: "----:com.apple.iTunes:Acoustid Id",
|
|
79
|
+
},
|
|
80
|
+
musicbrainzTrackId: {
|
|
81
|
+
id3v2: { frame: "UFID", description: "http://musicbrainz.org" },
|
|
82
|
+
vorbis: "MUSICBRAINZ_TRACKID",
|
|
83
|
+
mp4: "----:com.apple.iTunes:MusicBrainz Track Id",
|
|
84
|
+
},
|
|
85
|
+
musicbrainzReleaseId: {
|
|
86
|
+
id3v2: { frame: "TXXX", description: "MusicBrainz Album Id" },
|
|
87
|
+
vorbis: "MUSICBRAINZ_ALBUMID",
|
|
88
|
+
mp4: "----:com.apple.iTunes:MusicBrainz Album Id",
|
|
89
|
+
},
|
|
90
|
+
musicbrainzArtistId: {
|
|
91
|
+
id3v2: { frame: "TXXX", description: "MusicBrainz Artist Id" },
|
|
92
|
+
vorbis: "MUSICBRAINZ_ARTISTID",
|
|
93
|
+
mp4: "----:com.apple.iTunes:MusicBrainz Artist Id",
|
|
94
|
+
},
|
|
95
|
+
musicbrainzReleaseGroupId: {
|
|
96
|
+
id3v2: { frame: "TXXX", description: "MusicBrainz Release Group Id" },
|
|
97
|
+
vorbis: "MUSICBRAINZ_RELEASEGROUPID",
|
|
98
|
+
mp4: "----:com.apple.iTunes:MusicBrainz Release Group Id",
|
|
99
|
+
},
|
|
100
|
+
albumArtist: {
|
|
101
|
+
id3v2: { frame: "TPE2" },
|
|
102
|
+
vorbis: "ALBUMARTIST",
|
|
103
|
+
mp4: "aART",
|
|
104
|
+
},
|
|
105
|
+
composer: {
|
|
106
|
+
id3v2: { frame: "TCOM" },
|
|
107
|
+
vorbis: "COMPOSER",
|
|
108
|
+
mp4: "©wrt",
|
|
109
|
+
},
|
|
110
|
+
discNumber: {
|
|
111
|
+
id3v2: { frame: "TPOS" },
|
|
112
|
+
vorbis: "DISCNUMBER",
|
|
113
|
+
mp4: "disk",
|
|
114
|
+
},
|
|
115
|
+
totalTracks: {
|
|
116
|
+
id3v2: { frame: "TRCK" }, // Part of TRCK frame
|
|
117
|
+
vorbis: "TRACKTOTAL",
|
|
118
|
+
mp4: "trkn", // Part of trkn atom
|
|
119
|
+
},
|
|
120
|
+
totalDiscs: {
|
|
121
|
+
id3v2: { frame: "TPOS" }, // Part of TPOS frame
|
|
122
|
+
vorbis: "DISCTOTAL",
|
|
123
|
+
mp4: "disk", // Part of disk atom
|
|
124
|
+
},
|
|
125
|
+
bpm: {
|
|
126
|
+
id3v2: { frame: "TBPM" },
|
|
127
|
+
vorbis: "BPM",
|
|
128
|
+
mp4: "tmpo",
|
|
129
|
+
},
|
|
130
|
+
compilation: {
|
|
131
|
+
id3v2: { frame: "TCMP" },
|
|
132
|
+
vorbis: "COMPILATION",
|
|
133
|
+
mp4: "cpil",
|
|
134
|
+
},
|
|
135
|
+
titleSort: {
|
|
136
|
+
id3v2: { frame: "TSOT" },
|
|
137
|
+
vorbis: "TITLESORT",
|
|
138
|
+
mp4: "sonm",
|
|
139
|
+
},
|
|
140
|
+
artistSort: {
|
|
141
|
+
id3v2: { frame: "TSOP" },
|
|
142
|
+
vorbis: "ARTISTSORT",
|
|
143
|
+
mp4: "soar",
|
|
144
|
+
},
|
|
145
|
+
albumSort: {
|
|
146
|
+
id3v2: { frame: "TSOA" },
|
|
147
|
+
vorbis: "ALBUMSORT",
|
|
148
|
+
mp4: "soal",
|
|
149
|
+
},
|
|
150
|
+
// ReplayGain mappings
|
|
151
|
+
replayGainTrackGain: {
|
|
152
|
+
id3v2: { frame: "TXXX", description: "ReplayGain_Track_Gain" },
|
|
153
|
+
vorbis: "REPLAYGAIN_TRACK_GAIN",
|
|
154
|
+
mp4: "----:com.apple.iTunes:replaygain_track_gain",
|
|
155
|
+
},
|
|
156
|
+
replayGainTrackPeak: {
|
|
157
|
+
id3v2: { frame: "TXXX", description: "ReplayGain_Track_Peak" },
|
|
158
|
+
vorbis: "REPLAYGAIN_TRACK_PEAK",
|
|
159
|
+
mp4: "----:com.apple.iTunes:replaygain_track_peak",
|
|
160
|
+
},
|
|
161
|
+
replayGainAlbumGain: {
|
|
162
|
+
id3v2: { frame: "TXXX", description: "ReplayGain_Album_Gain" },
|
|
163
|
+
vorbis: "REPLAYGAIN_ALBUM_GAIN",
|
|
164
|
+
mp4: "----:com.apple.iTunes:replaygain_album_gain",
|
|
165
|
+
},
|
|
166
|
+
replayGainAlbumPeak: {
|
|
167
|
+
id3v2: { frame: "TXXX", description: "ReplayGain_Album_Peak" },
|
|
168
|
+
vorbis: "REPLAYGAIN_ALBUM_PEAK",
|
|
169
|
+
mp4: "----:com.apple.iTunes:replaygain_album_peak",
|
|
170
|
+
},
|
|
171
|
+
// Apple Sound Check mapping
|
|
172
|
+
appleSoundCheck: {
|
|
173
|
+
id3v2: { frame: "TXXX", description: "iTunNORM" },
|
|
174
|
+
vorbis: "ITUNNORM", // Some tools store it in Vorbis comments too
|
|
175
|
+
mp4: "----:com.apple.iTunes:iTunNORM",
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Picture types as defined by ID3v2 APIC frame.
|
|
180
|
+
* Standard picture type codes used across different formats
|
|
181
|
+
* to categorize embedded images.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* // Set front cover art
|
|
186
|
+
* const coverArt = {
|
|
187
|
+
* type: PictureType.FrontCover,
|
|
188
|
+
* mimeType: "image/jpeg",
|
|
189
|
+
* data: imageData
|
|
190
|
+
* };
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export var PictureType;
|
|
194
|
+
(function (PictureType) {
|
|
195
|
+
PictureType[PictureType["Other"] = 0] = "Other";
|
|
196
|
+
PictureType[PictureType["FileIcon"] = 1] = "FileIcon";
|
|
197
|
+
PictureType[PictureType["OtherFileIcon"] = 2] = "OtherFileIcon";
|
|
198
|
+
PictureType[PictureType["FrontCover"] = 3] = "FrontCover";
|
|
199
|
+
PictureType[PictureType["BackCover"] = 4] = "BackCover";
|
|
200
|
+
PictureType[PictureType["LeafletPage"] = 5] = "LeafletPage";
|
|
201
|
+
PictureType[PictureType["Media"] = 6] = "Media";
|
|
202
|
+
PictureType[PictureType["LeadArtist"] = 7] = "LeadArtist";
|
|
203
|
+
PictureType[PictureType["Artist"] = 8] = "Artist";
|
|
204
|
+
PictureType[PictureType["Conductor"] = 9] = "Conductor";
|
|
205
|
+
PictureType[PictureType["Band"] = 10] = "Band";
|
|
206
|
+
PictureType[PictureType["Composer"] = 11] = "Composer";
|
|
207
|
+
PictureType[PictureType["Lyricist"] = 12] = "Lyricist";
|
|
208
|
+
PictureType[PictureType["RecordingLocation"] = 13] = "RecordingLocation";
|
|
209
|
+
PictureType[PictureType["DuringRecording"] = 14] = "DuringRecording";
|
|
210
|
+
PictureType[PictureType["DuringPerformance"] = 15] = "DuringPerformance";
|
|
211
|
+
PictureType[PictureType["MovieScreenCapture"] = 16] = "MovieScreenCapture";
|
|
212
|
+
PictureType[PictureType["ColouredFish"] = 17] = "ColouredFish";
|
|
213
|
+
PictureType[PictureType["Illustration"] = 18] = "Illustration";
|
|
214
|
+
PictureType[PictureType["BandLogo"] = 19] = "BandLogo";
|
|
215
|
+
PictureType[PictureType["PublisherLogo"] = 20] = "PublisherLogo";
|
|
216
|
+
})(PictureType || (PictureType = {}));
|
|
217
|
+
/**
|
|
218
|
+
* Map of bitrate control mode names to their numeric values.
|
|
219
|
+
* Used for converting between string representations and numeric codes
|
|
220
|
+
* stored in MP4/M4A files.
|
|
221
|
+
*/
|
|
222
|
+
export const BITRATE_CONTROL_MODE_VALUES = {
|
|
223
|
+
Constant: 0,
|
|
224
|
+
LongTermAverage: 1,
|
|
225
|
+
VariableConstrained: 2,
|
|
226
|
+
Variable: 3,
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Map of numeric values to bitrate control mode names.
|
|
230
|
+
* Used for converting numeric codes from MP4/M4A files
|
|
231
|
+
* to human-readable string representations.
|
|
232
|
+
*/
|
|
233
|
+
export const BITRATE_CONTROL_MODE_NAMES = {
|
|
234
|
+
0: "Constant",
|
|
235
|
+
1: "LongTermAverage",
|
|
236
|
+
2: "VariableConstrained",
|
|
237
|
+
3: "Variable",
|
|
238
|
+
};
|
|
239
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA4MH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA4C;IACxE,0DAA0D;IAC1D,KAAK,EAAE;QACL,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QACxB,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,MAAM;KACZ;IACD,MAAM,EAAE;QACN,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QACxB,MAAM,EAAE,QAAQ;QAChB,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,MAAM;KACZ;IACD,KAAK,EAAE;QACL,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QACxB,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,MAAM;KACZ;IACD,OAAO,EAAE;QACP,KA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a,CAAA;IACb,2DAAe,CAAA;IACf,+CAAS,CAAA;IACT,yDAAc,CAAA;IACd,iDAAU,CAAA;IACV,uDAAa,CAAA;IACb,8CAAS,CAAA;IACT,sDAAa,CAAA;IACb,sDAAa,CAAA;IACb,wEAAsB,CAAA;IACtB,oEAAoB,CAAA;IACpB,wEAAsB,CAAA;IACtB,0EAAuB,CAAA;IACvB,8DAAiB,CAAA;IACjB,8DAAiB,CAAA;IACjB,sDAAa,CAAA;IACb,gEAAkB,CAAA;AACpB,CAAC,EAtBW,WAAW,KAAX,WAAW,QAsBtB;AAiBD;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAuC;IAC7E,QAAQ,EAAE,CAAC;IACX,eAAe,EAAE,CAAC;IAClB,mBAAmB,EAAE,CAAC;IACtB,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAuC;IAC5E,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,iBAAiB;IACpB,CAAC,EAAE,qBAAqB;IACxB,CAAC,EAAE,UAAU;CACd,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File reading utilities for taglib-wasm
|
|
3
|
+
* Provides cross-runtime support for reading files from various sources
|
|
4
|
+
*/
|
|
5
|
+
import { EnvironmentError, FileOperationError } from "../errors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Read a file's data from various sources.
|
|
8
|
+
* Supports file paths (Node.js/Deno/Bun), buffers, and File objects (browser).
|
|
9
|
+
*
|
|
10
|
+
* @param file - File path, Uint8Array, ArrayBuffer, or File object
|
|
11
|
+
* @returns Promise resolving to Uint8Array of file data
|
|
12
|
+
* @throws {FileOperationError} If file read fails
|
|
13
|
+
* @throws {EnvironmentError} If environment doesn't support file paths
|
|
14
|
+
*/
|
|
15
|
+
export async function readFileData(file) {
|
|
16
|
+
// Already a Uint8Array
|
|
17
|
+
if (file instanceof Uint8Array) {
|
|
18
|
+
return file;
|
|
19
|
+
}
|
|
20
|
+
// ArrayBuffer - convert to Uint8Array
|
|
21
|
+
if (file instanceof ArrayBuffer) {
|
|
22
|
+
return new Uint8Array(file);
|
|
23
|
+
}
|
|
24
|
+
// File object (browser)
|
|
25
|
+
if (typeof File !== "undefined" && file instanceof File) {
|
|
26
|
+
return new Uint8Array(await file.arrayBuffer());
|
|
27
|
+
}
|
|
28
|
+
// String path - read from filesystem
|
|
29
|
+
if (typeof file === "string") {
|
|
30
|
+
// Check environment support first
|
|
31
|
+
const hasDeno = typeof globalThis.Deno !== "undefined";
|
|
32
|
+
const hasNode = typeof globalThis.process !== "undefined" &&
|
|
33
|
+
globalThis.process.versions &&
|
|
34
|
+
globalThis.process.versions.node;
|
|
35
|
+
const hasBun = typeof globalThis.Bun !== "undefined";
|
|
36
|
+
// If no runtime supports filesystem, throw EnvironmentError
|
|
37
|
+
if (!hasDeno && !hasNode && !hasBun) {
|
|
38
|
+
const env = "Browser";
|
|
39
|
+
throw new EnvironmentError(env, "does not support file path reading", "filesystem access");
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
// Deno
|
|
43
|
+
if (hasDeno) {
|
|
44
|
+
return await globalThis.Deno.readFile(file);
|
|
45
|
+
}
|
|
46
|
+
// Node.js
|
|
47
|
+
if (hasNode) {
|
|
48
|
+
const { readFile } = await import("fs/promises");
|
|
49
|
+
return new Uint8Array(await readFile(file));
|
|
50
|
+
}
|
|
51
|
+
// Bun
|
|
52
|
+
if (hasBun) {
|
|
53
|
+
const bunFile = globalThis.Bun.file(file);
|
|
54
|
+
return new Uint8Array(await bunFile.arrayBuffer());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
// Convert system file errors to FileOperationError
|
|
59
|
+
throw new FileOperationError("read", error.message, file);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const inputType = Object.prototype.toString.call(file);
|
|
63
|
+
throw new FileOperationError("read", `Invalid file input type: ${inputType}. Expected string path, Uint8Array, ArrayBuffer, or File object.`);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/utils/file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAA8C;IAE9C,uBAAuB;IACvB,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sCAAsC;IACtC,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;QAChC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,wBAAwB;IACxB,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACxD,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,qCAAqC;IACrC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,kCAAkC;QAClC,MAAM,OAAO,GAAG,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,CAAC;QAChE,MAAM,OAAO,GAAG,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW;YAC/D,UAAkB,CAAC,OAAO,CAAC,QAAQ;YACnC,UAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC5C,MAAM,MAAM,GAAG,OAAQ,UAAkB,CAAC,GAAG,KAAK,WAAW,CAAC;QAE9D,4DAA4D;QAC5D,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,GAAG,GAAG,SAAS,CAAC;YACtB,MAAM,IAAI,gBAAgB,CACxB,GAAG,EACH,oCAAoC,EACpC,mBAAmB,CACpB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,OAAO;YACP,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,MAAO,UAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACvD,CAAC;YAED,UAAU;YACV,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;gBACjD,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9C,CAAC;YAED,MAAM;YACN,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,OAAO,GAAI,UAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnD,OAAO,IAAI,UAAU,CAAC,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,mDAAmD;YACnD,MAAM,IAAI,kBAAkB,CAC1B,MAAM,EACL,KAAe,CAAC,OAAO,EACxB,IAAI,CACL,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,IAAI,kBAAkB,CAC1B,MAAM,EACN,4BAA4B,SAAS,kEAAkE,CACxG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File writing utilities for taglib-wasm
|
|
3
|
+
* Provides cross-runtime support for writing files
|
|
4
|
+
*/
|
|
5
|
+
import { EnvironmentError, FileOperationError } from "../errors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Write data to a file across different runtimes.
|
|
8
|
+
* Supports Node.js, Deno, and Bun environments.
|
|
9
|
+
*
|
|
10
|
+
* @param path - File path to write to
|
|
11
|
+
* @param data - Data to write (Uint8Array)
|
|
12
|
+
* @throws {FileOperationError} If file write fails
|
|
13
|
+
* @throws {EnvironmentError} If environment doesn't support file writing
|
|
14
|
+
*/
|
|
15
|
+
export async function writeFileData(path, data) {
|
|
16
|
+
try {
|
|
17
|
+
// Deno
|
|
18
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
19
|
+
await globalThis.Deno.writeFile(path, data);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Node.js
|
|
23
|
+
if (typeof globalThis.process !== "undefined" &&
|
|
24
|
+
globalThis.process.versions &&
|
|
25
|
+
globalThis.process.versions.node) {
|
|
26
|
+
const { writeFile } = await import("fs/promises");
|
|
27
|
+
await writeFile(path, data);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Bun
|
|
31
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
32
|
+
await globalThis.Bun.write(path, data);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// Convert system file errors to FileOperationError
|
|
38
|
+
throw new FileOperationError("write", error.message, path);
|
|
39
|
+
}
|
|
40
|
+
const env = typeof globalThis.Deno !== "undefined"
|
|
41
|
+
? "Deno"
|
|
42
|
+
: typeof globalThis.process !== "undefined"
|
|
43
|
+
? "Node.js"
|
|
44
|
+
: typeof globalThis.Bun !== "undefined"
|
|
45
|
+
? "Bun"
|
|
46
|
+
: "Browser";
|
|
47
|
+
throw new EnvironmentError(env, "does not support file path writing", "filesystem access");
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/utils/write.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG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,EACpC,mBAAmB,CACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview WebAssembly module interface for Cloudflare Workers
|
|
3
3
|
*/
|
|
4
|
-
import type { TagLibConfig, TagLibModule } from "./types
|
|
4
|
+
import type { TagLibConfig, TagLibModule } from "./types";
|
|
5
5
|
export type { TagLibModule };
|
|
6
6
|
/**
|
|
7
7
|
* Load and initialize the TagLib WebAssembly module for Cloudflare Workers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-workers.d.ts","sourceRoot":"","sources":["../../src/wasm-workers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"wasm-workers.d.ts","sourceRoot":"","sources":["../../src/wasm-workers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D,YAAY,EAAE,YAAY,EAAE,CAAC;AAc7B;;;;;;;;;;;;;GAaG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,UAAU,EACtB,MAAM,GAAE,YAAiB,GACxB,OAAO,CAAC,YAAY,CAAC,CAkEvB;AA4BD;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQrE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAYrE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAS7C"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview WebAssembly module interface for Cloudflare Workers
|
|
3
|
+
*/
|
|
4
|
+
import { TagLibInitializationError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Default configuration for taglib-wasm module in Workers environment
|
|
7
|
+
* Reduced memory limits to fit within Workers constraints
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_WORKERS_CONFIG = {
|
|
10
|
+
memory: {
|
|
11
|
+
initial: 8 * 1024 * 1024, // 8MB (reduced from 16MB)
|
|
12
|
+
maximum: 64 * 1024 * 1024, // 64MB (reduced from 256MB)
|
|
13
|
+
},
|
|
14
|
+
debug: false,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Load and initialize the TagLib WebAssembly module for Cloudflare Workers
|
|
18
|
+
*
|
|
19
|
+
* @param wasmBinary - The WebAssembly binary as Uint8Array
|
|
20
|
+
* @param config - Optional configuration for the Wasm module
|
|
21
|
+
* @returns Promise resolving to initialized TagLib module
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import wasmBinary from "../build/taglib.wasm.js";
|
|
26
|
+
*
|
|
27
|
+
* const taglib = await loadTagLibModuleForWorkers(wasmBinary);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function loadTagLibModuleForWorkers(wasmBinary, config = {}) {
|
|
31
|
+
const mergedConfig = { ...DEFAULT_WORKERS_CONFIG, ...config };
|
|
32
|
+
// Create Emscripten module configuration for Workers
|
|
33
|
+
const moduleConfig = {
|
|
34
|
+
wasmBinary,
|
|
35
|
+
wasmMemory: new WebAssembly.Memory({
|
|
36
|
+
initial: mergedConfig.memory.initial / (64 * 1024),
|
|
37
|
+
maximum: mergedConfig.memory.maximum / (64 * 1024),
|
|
38
|
+
}),
|
|
39
|
+
print: mergedConfig.debug ? console.log : () => { },
|
|
40
|
+
printErr: mergedConfig.debug ? console.error : () => { },
|
|
41
|
+
onRuntimeInitialized: () => {
|
|
42
|
+
if (mergedConfig.debug) {
|
|
43
|
+
console.log("taglib-wasm module initialized in Workers");
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
// Workers-specific settings
|
|
47
|
+
locateFile: () => {
|
|
48
|
+
// Return empty string since we're providing wasmBinary directly
|
|
49
|
+
return "";
|
|
50
|
+
},
|
|
51
|
+
// Disable file system access
|
|
52
|
+
noFSInit: true,
|
|
53
|
+
noExitRuntime: true,
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
// For Workers, we need to use a modified version of the Emscripten output
|
|
57
|
+
// that doesn't include Node.js/CommonJS dependencies
|
|
58
|
+
const TagLibWasm = await createWorkersCompatibleModule();
|
|
59
|
+
if (typeof TagLibWasm !== "function") {
|
|
60
|
+
throw new TagLibInitializationError("Failed to load taglib-wasm module for Workers. " +
|
|
61
|
+
"The module may not be properly bundled for the Workers environment.");
|
|
62
|
+
}
|
|
63
|
+
const wasmInstance = await TagLibWasm(moduleConfig);
|
|
64
|
+
// Ensure proper memory arrays are set up
|
|
65
|
+
if (!wasmInstance.HEAPU8) {
|
|
66
|
+
const buffer = wasmInstance.buffer || wasmInstance.wasmMemory?.buffer;
|
|
67
|
+
if (buffer) {
|
|
68
|
+
wasmInstance.HEAPU8 = new Uint8Array(buffer);
|
|
69
|
+
wasmInstance.HEAP8 = new Int8Array(buffer);
|
|
70
|
+
wasmInstance.HEAP16 = new Int16Array(buffer);
|
|
71
|
+
wasmInstance.HEAP32 = new Int32Array(buffer);
|
|
72
|
+
wasmInstance.HEAPU16 = new Uint16Array(buffer);
|
|
73
|
+
wasmInstance.HEAPU32 = new Uint32Array(buffer);
|
|
74
|
+
wasmInstance.HEAPF32 = new Float32Array(buffer);
|
|
75
|
+
wasmInstance.HEAPF64 = new Float64Array(buffer);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return wasmInstance;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof TagLibInitializationError) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
throw new TagLibInitializationError(`Failed to load taglib-wasm for Workers: ${error.message}`, { error: error.message });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a Workers-compatible version of the Emscripten module
|
|
89
|
+
* This function loads the Wasm module without Node.js/CommonJS dependencies
|
|
90
|
+
*/
|
|
91
|
+
async function createWorkersCompatibleModule() {
|
|
92
|
+
// In a real Workers environment, you would typically:
|
|
93
|
+
// 1. Use a build process to create a Workers-compatible version of taglib.js
|
|
94
|
+
// 2. Or inline the essential parts of the Emscripten runtime here
|
|
95
|
+
// 3. Or use dynamic import with proper bundling
|
|
96
|
+
// For now, we'll attempt to load the existing module with Workers compatibility
|
|
97
|
+
try {
|
|
98
|
+
// Try to import the existing module
|
|
99
|
+
const wasmModule = await import("../build/taglib-wrapper.js");
|
|
100
|
+
return wasmModule.default || wasmModule;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// If that fails, provide a fallback implementation
|
|
104
|
+
throw new TagLibInitializationError("Workers-compatible Wasm module not available. " +
|
|
105
|
+
"Please build with Workers target or use a bundler that supports Wasm modules. " +
|
|
106
|
+
`Original error: ${error.message}`, { error: error.message });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Convert a C string pointer to JavaScript string (Workers-compatible)
|
|
111
|
+
*/
|
|
112
|
+
export function cStringToJS(module, ptr) {
|
|
113
|
+
if (ptr === 0)
|
|
114
|
+
return "";
|
|
115
|
+
const view = new Uint8Array(module.HEAPU8.buffer, ptr);
|
|
116
|
+
let length = 0;
|
|
117
|
+
while (view[length] !== 0)
|
|
118
|
+
length++;
|
|
119
|
+
return new TextDecoder().decode(view.subarray(0, length));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Convert JavaScript string to C string (Workers-compatible)
|
|
123
|
+
*/
|
|
124
|
+
export function jsToCString(module, str) {
|
|
125
|
+
const encoder = new TextEncoder();
|
|
126
|
+
const bytes = encoder.encode(str + "\0");
|
|
127
|
+
// Use allocate if available, otherwise use _malloc
|
|
128
|
+
if (module.allocate && module.ALLOC_NORMAL !== undefined) {
|
|
129
|
+
return module.allocate(bytes, module.ALLOC_NORMAL);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const ptr = module._malloc(bytes.length);
|
|
133
|
+
module.HEAPU8.set(bytes, ptr);
|
|
134
|
+
return ptr;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Utility function to check if we're running in Cloudflare Workers
|
|
139
|
+
*/
|
|
140
|
+
export function isCloudflareWorkers() {
|
|
141
|
+
return (typeof globalThis !== "undefined" &&
|
|
142
|
+
typeof globalThis.caches !== "undefined" &&
|
|
143
|
+
typeof globalThis.Request !== "undefined" &&
|
|
144
|
+
typeof globalThis.Response !== "undefined" &&
|
|
145
|
+
typeof globalThis.process === "undefined" &&
|
|
146
|
+
typeof globalThis.Deno === "undefined");
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=wasm-workers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-workers.js","sourceRoot":"","sources":["../../src/wasm-workers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAKrD;;;GAGG;AACH,MAAM,sBAAsB,GAA2B;IACrD,MAAM,EAAE;QACN,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,0BAA0B;QACpD,OAAO,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,4BAA4B;KACxD;IACD,KAAK,EAAE,KAAK;CACb,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,UAAsB,EACtB,SAAuB,EAAE;IAEzB,MAAM,YAAY,GAAG,EAAE,GAAG,sBAAsB,EAAE,GAAG,MAAM,EAAE,CAAC;IAE9D,qDAAqD;IACrD,MAAM,YAAY,GAAG;QACnB,UAAU;QACV,UAAU,EAAE,IAAI,WAAW,CAAC,M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AAK,WAAW;QACxC,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW;QACzC,OAAO,UAAU,CAAC,QAAQ,KAAK,WAAW;QAC1C,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW;QAClD,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,CAChD,CAAC;AACJ,CAAC"}
|
package/dist/src/wasm.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.js","sourceRoot":"","sources":["../../src/wasm.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAkIH,sDAAsD"}
|
package/dist/src/web-utils.d.ts
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* const modifiedBuffer = await setCoverArtFromCanvas("song.mp3", canvas);
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
import type { Picture } from "./types
|
|
24
|
-
import { PictureType } from "./types
|
|
23
|
+
import type { Picture } from "./types";
|
|
24
|
+
import { PictureType } from "./types";
|
|
25
25
|
/**
|
|
26
26
|
* Convert a Picture object to a data URL for display in web browsers
|
|
27
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-utils.d.ts","sourceRoot":"","sources":["../../src/web-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"web-utils.d.ts","sourceRoot":"","sources":["../../src/web-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIzD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9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