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
package/dist/src/workers.ts
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Cloudflare Workers-specific TagLib API
|
|
3
|
-
*
|
|
4
|
-
* This module provides a specialized API for using TagLib in Cloudflare Workers
|
|
5
|
-
* and other edge computing environments where the standard Emscripten module
|
|
6
|
-
* loading may not work. It uses C-style function exports for compatibility.
|
|
7
|
-
*
|
|
8
|
-
* @module taglib-wasm/workers
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
AudioFormat,
|
|
13
|
-
AudioProperties,
|
|
14
|
-
ExtendedTag,
|
|
15
|
-
Tag,
|
|
16
|
-
TagLibConfig,
|
|
17
|
-
} from "./types.ts";
|
|
18
|
-
import {
|
|
19
|
-
cStringToJS,
|
|
20
|
-
jsToCString,
|
|
21
|
-
loadTagLibModuleForWorkers,
|
|
22
|
-
type TagLibModule,
|
|
23
|
-
} from "./wasm-workers.ts";
|
|
24
|
-
import { EnvironmentError, InvalidFormatError, MemoryError } from "./errors.ts";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Represents an audio file with metadata and properties (Workers-compatible).
|
|
28
|
-
* This implementation uses C-style function calls for Cloudflare Workers compatibility.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const file = taglib.openFile(audioBuffer);
|
|
33
|
-
*
|
|
34
|
-
* // Get metadata
|
|
35
|
-
* const tag = file.tag();
|
|
36
|
-
* console.log(tag.title);
|
|
37
|
-
*
|
|
38
|
-
* // Modify metadata
|
|
39
|
-
* file.setTitle("New Title");
|
|
40
|
-
* file.save();
|
|
41
|
-
*
|
|
42
|
-
* // Clean up
|
|
43
|
-
* file.dispose();
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export class AudioFileWorkers {
|
|
47
|
-
private module: TagLibModule;
|
|
48
|
-
private fileId: number;
|
|
49
|
-
private tagPtr: number;
|
|
50
|
-
private propsPtr: number;
|
|
51
|
-
|
|
52
|
-
constructor(module: TagLibModule, fileId: number) {
|
|
53
|
-
this.module = module;
|
|
54
|
-
this.fileId = fileId;
|
|
55
|
-
this.tagPtr = module._taglib_file_tag?.(fileId) || 0;
|
|
56
|
-
this.propsPtr = module._taglib_file_audioproperties?.(fileId) || 0;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Check if the file is valid and was loaded successfully.
|
|
61
|
-
* @returns true if the file is valid and can be processed
|
|
62
|
-
*/
|
|
63
|
-
isValid(): boolean {
|
|
64
|
-
return this.module._taglib_file_is_valid?.(this.fileId) !== 0;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get the file format.
|
|
69
|
-
* @returns Audio format (e.g., "MP3", "FLAC", "OGG")
|
|
70
|
-
*/
|
|
71
|
-
format(): AudioFormat {
|
|
72
|
-
const formatPtr = this.module._taglib_file_format?.(this.fileId) || 0;
|
|
73
|
-
if (formatPtr === 0) return "MP3"; // fallback
|
|
74
|
-
const formatStr = cStringToJS(this.module, formatPtr);
|
|
75
|
-
return formatStr as AudioFormat;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Get basic tag information.
|
|
80
|
-
* @returns Object containing title, artist, album, etc.
|
|
81
|
-
*/
|
|
82
|
-
tag(): Tag {
|
|
83
|
-
if (this.tagPtr === 0) return {};
|
|
84
|
-
|
|
85
|
-
const title = this.module._taglib_tag_title?.(this.tagPtr) || 0;
|
|
86
|
-
const artist = this.module._taglib_tag_artist?.(this.tagPtr) || 0;
|
|
87
|
-
const album = this.module._taglib_tag_album?.(this.tagPtr) || 0;
|
|
88
|
-
const comment = this.module._taglib_tag_comment?.(this.tagPtr) || 0;
|
|
89
|
-
const genre = this.module._taglib_tag_genre?.(this.tagPtr) || 0;
|
|
90
|
-
const year = this.module._taglib_tag_year?.(this.tagPtr) || 0;
|
|
91
|
-
const track = this.module._taglib_tag_track?.(this.tagPtr) || 0;
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
title: title ? cStringToJS(this.module, title) : undefined,
|
|
95
|
-
artist: artist ? cStringToJS(this.module, artist) : undefined,
|
|
96
|
-
album: album ? cStringToJS(this.module, album) : undefined,
|
|
97
|
-
comment: comment ? cStringToJS(this.module, comment) : undefined,
|
|
98
|
-
genre: genre ? cStringToJS(this.module, genre) : undefined,
|
|
99
|
-
year: year || undefined,
|
|
100
|
-
track: track || undefined,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Get audio properties (duration, bitrate, etc.).
|
|
106
|
-
* @returns Audio properties or null if unavailable
|
|
107
|
-
*/
|
|
108
|
-
audioProperties(): AudioProperties | null {
|
|
109
|
-
if (this.propsPtr === 0) return null;
|
|
110
|
-
|
|
111
|
-
const length =
|
|
112
|
-
this.module._taglib_audioproperties_length?.(this.propsPtr) || 0;
|
|
113
|
-
const bitrate =
|
|
114
|
-
this.module._taglib_audioproperties_bitrate?.(this.propsPtr) || 0;
|
|
115
|
-
const sampleRate = this.module._taglib_audioproperties_samplerate?.(
|
|
116
|
-
this.propsPtr,
|
|
117
|
-
) || 0;
|
|
118
|
-
const channels = this.module._taglib_audioproperties_channels?.(
|
|
119
|
-
this.propsPtr,
|
|
120
|
-
) || 0;
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
length,
|
|
124
|
-
bitrate,
|
|
125
|
-
sampleRate,
|
|
126
|
-
channels,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Set the title tag.
|
|
132
|
-
* @param title - New title value
|
|
133
|
-
*/
|
|
134
|
-
setTitle(title: string): void {
|
|
135
|
-
if (this.tagPtr === 0) return;
|
|
136
|
-
const titlePtr = jsToCString(this.module, title);
|
|
137
|
-
this.module._taglib_tag_set_title?.(this.tagPtr, titlePtr);
|
|
138
|
-
this.module._free(titlePtr);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Set the artist tag.
|
|
143
|
-
* @param artist - New artist value
|
|
144
|
-
*/
|
|
145
|
-
setArtist(artist: string): void {
|
|
146
|
-
if (this.tagPtr === 0) return;
|
|
147
|
-
const artistPtr = jsToCString(this.module, artist);
|
|
148
|
-
this.module._taglib_tag_set_artist?.(this.tagPtr, artistPtr);
|
|
149
|
-
this.module._free(artistPtr);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Set the album tag.
|
|
154
|
-
* @param album - New album value
|
|
155
|
-
*/
|
|
156
|
-
setAlbum(album: string): void {
|
|
157
|
-
if (this.tagPtr === 0) return;
|
|
158
|
-
const albumPtr = jsToCString(this.module, album);
|
|
159
|
-
this.module._taglib_tag_set_album?.(this.tagPtr, albumPtr);
|
|
160
|
-
this.module._free(albumPtr);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Set the comment tag.
|
|
165
|
-
* @param comment - New comment value
|
|
166
|
-
*/
|
|
167
|
-
setComment(comment: string): void {
|
|
168
|
-
if (this.tagPtr === 0) return;
|
|
169
|
-
const commentPtr = jsToCString(this.module, comment);
|
|
170
|
-
this.module._taglib_tag_set_comment?.(this.tagPtr, commentPtr);
|
|
171
|
-
this.module._free(commentPtr);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Set the genre tag.
|
|
176
|
-
* @param genre - New genre value
|
|
177
|
-
*/
|
|
178
|
-
setGenre(genre: string): void {
|
|
179
|
-
if (this.tagPtr === 0) return;
|
|
180
|
-
const genrePtr = jsToCString(this.module, genre);
|
|
181
|
-
this.module._taglib_tag_set_genre?.(this.tagPtr, genrePtr);
|
|
182
|
-
this.module._free(genrePtr);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Set the year tag.
|
|
187
|
-
* @param year - Release year
|
|
188
|
-
*/
|
|
189
|
-
setYear(year: number): void {
|
|
190
|
-
if (this.tagPtr === 0) return;
|
|
191
|
-
this.module._taglib_tag_set_year?.(this.tagPtr, year);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Set the track number tag.
|
|
196
|
-
* @param track - Track number
|
|
197
|
-
*/
|
|
198
|
-
setTrack(track: number): void {
|
|
199
|
-
if (this.tagPtr === 0) return;
|
|
200
|
-
this.module._taglib_tag_set_track?.(this.tagPtr, track);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Save changes to the file.
|
|
205
|
-
* Note: In Workers context, this saves to the in-memory buffer only.
|
|
206
|
-
* @returns true if save was successful
|
|
207
|
-
*/
|
|
208
|
-
save(): boolean {
|
|
209
|
-
if (this.fileId !== 0) {
|
|
210
|
-
return this.module._taglib_file_save?.(this.fileId) !== 0;
|
|
211
|
-
}
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Get the current file buffer after modifications.
|
|
217
|
-
* Note: This is not implemented in the Workers API.
|
|
218
|
-
* @returns Empty Uint8Array (not implemented)
|
|
219
|
-
* @deprecated Use the Core API for this functionality
|
|
220
|
-
*/
|
|
221
|
-
getFileBuffer(): Uint8Array {
|
|
222
|
-
console.warn(
|
|
223
|
-
"getFileBuffer() is not implemented in Workers API. Use Core API for this functionality.",
|
|
224
|
-
);
|
|
225
|
-
return new Uint8Array(0);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Get extended metadata with format-agnostic field names.
|
|
230
|
-
* Note: Currently returns only basic fields in Workers API.
|
|
231
|
-
* @returns Extended tag object with basic fields populated
|
|
232
|
-
*/
|
|
233
|
-
extendedTag(): ExtendedTag {
|
|
234
|
-
const basicTag = this.tag();
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
...basicTag,
|
|
238
|
-
// Advanced fields placeholder - would be populated by PropertyMap reading
|
|
239
|
-
acoustidFingerprint: undefined,
|
|
240
|
-
acoustidId: undefined,
|
|
241
|
-
musicbrainzTrackId: undefined,
|
|
242
|
-
musicbrainzReleaseId: undefined,
|
|
243
|
-
musicbrainzArtistId: undefined,
|
|
244
|
-
musicbrainzReleaseGroupId: undefined,
|
|
245
|
-
albumArtist: undefined,
|
|
246
|
-
composer: undefined,
|
|
247
|
-
discNumber: undefined,
|
|
248
|
-
totalTracks: undefined,
|
|
249
|
-
totalDiscs: undefined,
|
|
250
|
-
bpm: undefined,
|
|
251
|
-
compilation: undefined,
|
|
252
|
-
titleSort: undefined,
|
|
253
|
-
artistSort: undefined,
|
|
254
|
-
albumSort: undefined,
|
|
255
|
-
replayGainTrackGain: undefined,
|
|
256
|
-
replayGainTrackPeak: undefined,
|
|
257
|
-
replayGainAlbumGain: undefined,
|
|
258
|
-
replayGainAlbumPeak: undefined,
|
|
259
|
-
appleSoundCheck: undefined,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Set extended metadata using format-agnostic field names.
|
|
265
|
-
* Note: Currently only supports basic fields in Workers API.
|
|
266
|
-
* @param tag - Partial extended tag object with fields to update
|
|
267
|
-
*/
|
|
268
|
-
setExtendedTag(tag: Partial<ExtendedTag>): void {
|
|
269
|
-
if (tag.title !== undefined) this.setTitle(tag.title);
|
|
270
|
-
if (tag.artist !== undefined) this.setArtist(tag.artist);
|
|
271
|
-
if (tag.album !== undefined) this.setAlbum(tag.album);
|
|
272
|
-
if (tag.comment !== undefined) this.setComment(tag.comment);
|
|
273
|
-
if (tag.genre !== undefined) this.setGenre(tag.genre);
|
|
274
|
-
if (tag.year !== undefined) this.setYear(tag.year);
|
|
275
|
-
if (tag.track !== undefined) this.setTrack(tag.track);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Clean up resources.
|
|
280
|
-
* Always call this when done to prevent memory leaks.
|
|
281
|
-
*/
|
|
282
|
-
dispose(): void {
|
|
283
|
-
if (this.fileId !== 0) {
|
|
284
|
-
this.module._taglib_file_delete?.(this.fileId);
|
|
285
|
-
this.fileId = 0;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Main TagLib class for Cloudflare Workers.
|
|
292
|
-
* Provides methods to initialize the library and open audio files
|
|
293
|
-
* in edge computing environments.
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```typescript
|
|
297
|
-
* import wasmBinary from "../build/taglib.wasm";
|
|
298
|
-
*
|
|
299
|
-
* // Initialize TagLib
|
|
300
|
-
* const taglib = await TagLibWorkers.initialize(wasmBinary);
|
|
301
|
-
*
|
|
302
|
-
* // Process audio file
|
|
303
|
-
* const file = taglib.openFile(audioBuffer);
|
|
304
|
-
* const metadata = file.tag();
|
|
305
|
-
* file.dispose();
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
export class TagLibWorkers {
|
|
309
|
-
private module: TagLibModule;
|
|
310
|
-
|
|
311
|
-
private constructor(module: TagLibModule) {
|
|
312
|
-
this.module = module;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Initialize TagLib for Workers with Wasm binary
|
|
317
|
-
*
|
|
318
|
-
* @param wasmBinary - The WebAssembly binary as Uint8Array
|
|
319
|
-
* @param config - Optional configuration for the Wasm module
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```typescript
|
|
323
|
-
* // In a Cloudflare Worker
|
|
324
|
-
* import wasmBinary from "../build/taglib.wasm";
|
|
325
|
-
*
|
|
326
|
-
* const taglib = await TagLibWorkers.initialize(wasmBinary);
|
|
327
|
-
* const file = taglib.open(audioBuffer);
|
|
328
|
-
* const metadata = file.tag();
|
|
329
|
-
* ```
|
|
330
|
-
*/
|
|
331
|
-
static async initialize(
|
|
332
|
-
wasmBinary: Uint8Array,
|
|
333
|
-
config?: TagLibConfig,
|
|
334
|
-
): Promise<TagLibWorkers> {
|
|
335
|
-
const module = await loadTagLibModuleForWorkers(wasmBinary, config);
|
|
336
|
-
return new TagLibWorkers(module);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Open an audio file from a buffer.
|
|
341
|
-
*
|
|
342
|
-
* @param buffer - Audio file data as Uint8Array
|
|
343
|
-
* @returns AudioFileWorkers instance
|
|
344
|
-
* @throws {Error} If Wasm module is not initialized
|
|
345
|
-
* @throws {Error} If file format is invalid or unsupported
|
|
346
|
-
* @throws {Error} If Workers API C-style functions are not available
|
|
347
|
-
*
|
|
348
|
-
* @example
|
|
349
|
-
* ```typescript
|
|
350
|
-
* const audioData = new Uint8Array(await request.arrayBuffer());
|
|
351
|
-
* const file = taglib.open(audioData);
|
|
352
|
-
* ```
|
|
353
|
-
*/
|
|
354
|
-
open(buffer: Uint8Array): AudioFileWorkers {
|
|
355
|
-
if (!this.module.HEAPU8) {
|
|
356
|
-
throw new MemoryError(
|
|
357
|
-
"Wasm module not properly initialized: missing HEAPU8. " +
|
|
358
|
-
"The module may not have loaded correctly in the Workers environment.",
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Use Emscripten's allocate function for proper memory management
|
|
363
|
-
let dataPtr: number;
|
|
364
|
-
if (this.module.allocate && this.module.ALLOC_NORMAL !== undefined) {
|
|
365
|
-
dataPtr = this.module.allocate(buffer, this.module.ALLOC_NORMAL);
|
|
366
|
-
} else {
|
|
367
|
-
dataPtr = this.module._malloc(buffer.length);
|
|
368
|
-
this.module.HEAPU8.set(buffer, dataPtr);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (!this.module._taglib_file_new_from_buffer) {
|
|
372
|
-
throw new EnvironmentError(
|
|
373
|
-
"Workers",
|
|
374
|
-
"requires C-style functions which are not available. Use the Core API instead for this environment",
|
|
375
|
-
"C-style function exports",
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const fileId = this.module._taglib_file_new_from_buffer(
|
|
380
|
-
dataPtr,
|
|
381
|
-
buffer.length,
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
if (fileId === 0) {
|
|
385
|
-
// Free the allocated memory since file creation failed
|
|
386
|
-
this.module._free(dataPtr);
|
|
387
|
-
throw new InvalidFormatError(
|
|
388
|
-
"Failed to open audio file. File format may be invalid or not supported",
|
|
389
|
-
buffer.length,
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// Free the temporary buffer copy (TagLib has made its own copy in ByteVector)
|
|
394
|
-
this.module._free(dataPtr);
|
|
395
|
-
|
|
396
|
-
return new AudioFileWorkers(this.module, fileId);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* @deprecated Use `open()` instead. This method will be removed in the next major version.
|
|
401
|
-
* Open an audio file from a buffer (backward compatibility).
|
|
402
|
-
* @param buffer Audio file data as Uint8Array
|
|
403
|
-
* @returns Audio file instance
|
|
404
|
-
*/
|
|
405
|
-
openFile(buffer: Uint8Array): AudioFileWorkers {
|
|
406
|
-
return this.open(buffer);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Get the underlying Wasm module for advanced usage.
|
|
411
|
-
* @returns The initialized TagLib Wasm module
|
|
412
|
-
*/
|
|
413
|
-
getModule(): TagLibModule {
|
|
414
|
-
return this.module;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Utility function to process audio metadata in a Cloudflare Worker
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* ```typescript
|
|
423
|
-
* export default {
|
|
424
|
-
* async fetch(request: Request): Promise<Response> {
|
|
425
|
-
* if (request.method === "POST") {
|
|
426
|
-
* const audioData = new Uint8Array(await request.arrayBuffer());
|
|
427
|
-
* const metadata = await processAudioMetadata(wasmBinary, audioData);
|
|
428
|
-
* return Response.json(metadata);
|
|
429
|
-
* }
|
|
430
|
-
* return new Response("Method not allowed", { status: 405 });
|
|
431
|
-
* }
|
|
432
|
-
* };
|
|
433
|
-
* ```
|
|
434
|
-
*/
|
|
435
|
-
export async function processAudioMetadata(
|
|
436
|
-
wasmBinary: Uint8Array,
|
|
437
|
-
audioData: Uint8Array,
|
|
438
|
-
config?: TagLibConfig,
|
|
439
|
-
): Promise<
|
|
440
|
-
{ tag: Tag; properties: AudioProperties | null; format: AudioFormat }
|
|
441
|
-
> {
|
|
442
|
-
const taglib = await TagLibWorkers.initialize(wasmBinary, config);
|
|
443
|
-
const file = taglib.open(audioData);
|
|
444
|
-
|
|
445
|
-
try {
|
|
446
|
-
const tag = file.tag();
|
|
447
|
-
const properties = file.audioProperties();
|
|
448
|
-
const format = file.format();
|
|
449
|
-
|
|
450
|
-
return { tag, properties, format };
|
|
451
|
-
} finally {
|
|
452
|
-
file.dispose();
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Re-export commonly used types for convenience.
|
|
458
|
-
* These types define the structure of metadata, audio properties,
|
|
459
|
-
* and configuration options.
|
|
460
|
-
*/
|
|
461
|
-
export type { AudioFormat, AudioProperties, ExtendedTag, Tag, TagLibConfig };
|
package/dist/src/write.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EnvironmentError, FileOperationError } from "../errors.ts";
|
|
2
|
-
async function writeFileData(path, data) {
|
|
3
|
-
try {
|
|
4
|
-
if (typeof globalThis.Deno !== "undefined") {
|
|
5
|
-
await globalThis.Deno.writeFile(path, data);
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
if (typeof globalThis.process !== "undefined" && globalThis.process.versions && globalThis.process.versions.node) {
|
|
9
|
-
const { writeFile } = await import("fs/promises");
|
|
10
|
-
await writeFile(path, data);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (typeof globalThis.Bun !== "undefined") {
|
|
14
|
-
await globalThis.Bun.write(path, data);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
} catch (error) {
|
|
18
|
-
throw new FileOperationError(
|
|
19
|
-
"write",
|
|
20
|
-
error.message,
|
|
21
|
-
path
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
const env = typeof globalThis.Deno !== "undefined" ? "Deno" : typeof globalThis.process !== "undefined" ? "Node.js" : typeof globalThis.Bun !== "undefined" ? "Bun" : "Browser";
|
|
25
|
-
throw new EnvironmentError(
|
|
26
|
-
env,
|
|
27
|
-
"does not support file path writing",
|
|
28
|
-
"filesystem access"
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
writeFileData
|
|
33
|
-
};
|
package/index.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main module exports for taglib-wasm
|
|
3
|
-
*
|
|
4
|
-
* TagLib v2.1 compiled to WebAssembly with TypeScript bindings
|
|
5
|
-
* for universal audio metadata handling across all JavaScript runtimes.
|
|
6
|
-
*
|
|
7
|
-
* @module taglib-wasm
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // Using the Core API
|
|
12
|
-
* import { TagLib } from "taglib-wasm";
|
|
13
|
-
*
|
|
14
|
-
* const taglib = await TagLib.initialize();
|
|
15
|
-
* const file = await taglib.open(audioBuffer);
|
|
16
|
-
* const tag = file.tag();
|
|
17
|
-
* console.log(tag.title);
|
|
18
|
-
* file.dispose();
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // Using the Simple API
|
|
24
|
-
* import { readTags, applyTags } from "taglib-wasm/simple";
|
|
25
|
-
*
|
|
26
|
-
* const tags = await readTags("song.mp3");
|
|
27
|
-
* console.log(tags.artist);
|
|
28
|
-
*
|
|
29
|
-
* const modified = await applyTags("song.mp3", {
|
|
30
|
-
* artist: "New Artist",
|
|
31
|
-
* album: "New Album"
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Core API exports for advanced usage with full control.
|
|
38
|
-
* @see {@link TagLib} - Main TagLib class
|
|
39
|
-
* @see {@link AudioFile} - Audio file interface
|
|
40
|
-
* @see {@link createTagLib} - Factory function for creating TagLib instances
|
|
41
|
-
*/
|
|
42
|
-
export {
|
|
43
|
-
AudioFileImpl as AudioFile,
|
|
44
|
-
createTagLib,
|
|
45
|
-
TagLib,
|
|
46
|
-
} from "./src/taglib.ts";
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Error types for proper error handling and debugging.
|
|
50
|
-
* @see {@link TagLibError} - Base error class for all TagLib errors
|
|
51
|
-
* @see {@link TagLibInitializationError} - Wasm initialization failures
|
|
52
|
-
* @see {@link InvalidFormatError} - Invalid or corrupted file format
|
|
53
|
-
* @see {@link UnsupportedFormatError} - Valid but unsupported format
|
|
54
|
-
* @see {@link FileOperationError} - File read/write/save failures
|
|
55
|
-
* @see {@link MetadataError} - Tag reading/writing failures
|
|
56
|
-
* @see {@link MemoryError} - Wasm memory allocation issues
|
|
57
|
-
* @see {@link EnvironmentError} - Runtime/environment issues
|
|
58
|
-
*/
|
|
59
|
-
export {
|
|
60
|
-
EnvironmentError,
|
|
61
|
-
FileOperationError,
|
|
62
|
-
InvalidFormatError,
|
|
63
|
-
isEnvironmentError,
|
|
64
|
-
isFileOperationError,
|
|
65
|
-
isInvalidFormatError,
|
|
66
|
-
isMemoryError,
|
|
67
|
-
isMetadataError,
|
|
68
|
-
isTagLibError,
|
|
69
|
-
isUnsupportedFormatError,
|
|
70
|
-
MemoryError,
|
|
71
|
-
MetadataError,
|
|
72
|
-
SUPPORTED_FORMATS,
|
|
73
|
-
TagLibError,
|
|
74
|
-
TagLibInitializationError,
|
|
75
|
-
UnsupportedFormatError,
|
|
76
|
-
} from "./src/errors.ts";
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Simple API exports for easy tag reading and writing.
|
|
80
|
-
* @see {@link readTags} - Read metadata from audio files
|
|
81
|
-
* @see {@link applyTags} - Apply metadata changes and return modified buffer
|
|
82
|
-
* @see {@link updateTags} - Update metadata and save to disk
|
|
83
|
-
* @see {@link writeTags} - Deprecated alias for applyTags
|
|
84
|
-
* @see {@link readProperties} - Read audio properties
|
|
85
|
-
* @see {@link readPictures} - Read cover art/pictures
|
|
86
|
-
* @see {@link applyPictures} - Apply pictures to audio files
|
|
87
|
-
* @see {@link getCoverArt} - Get primary cover art data
|
|
88
|
-
* @see {@link setCoverArt} - Set primary cover art
|
|
89
|
-
*/
|
|
90
|
-
export {
|
|
91
|
-
addPicture,
|
|
92
|
-
applyPictures,
|
|
93
|
-
applyTags,
|
|
94
|
-
clearPictures,
|
|
95
|
-
clearTags,
|
|
96
|
-
findPictureByType,
|
|
97
|
-
getCoverArt,
|
|
98
|
-
getFormat,
|
|
99
|
-
getPictureMetadata,
|
|
100
|
-
isValidAudioFile,
|
|
101
|
-
readPictures,
|
|
102
|
-
readProperties,
|
|
103
|
-
readTags,
|
|
104
|
-
replacePictureByType,
|
|
105
|
-
setCoverArt,
|
|
106
|
-
updateTags
|
|
107
|
-
} from "./src/simple.ts";
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Constants and utilities for tag name validation.
|
|
111
|
-
* @see {@link Tags} - Standard tag name constants
|
|
112
|
-
* @see {@link FormatMappings} - Format-specific field mappings
|
|
113
|
-
* @see {@link isValidTagName} - Validate tag names
|
|
114
|
-
* @see {@link getAllTagNames} - Get all valid tag names
|
|
115
|
-
*/
|
|
116
|
-
export {
|
|
117
|
-
FormatMappings,
|
|
118
|
-
getAllTagNames,
|
|
119
|
-
isValidTagName,
|
|
120
|
-
Tags,
|
|
121
|
-
} from "./src/constants.ts";
|
|
122
|
-
/**
|
|
123
|
-
* File I/O utilities for cover art operations.
|
|
124
|
-
* @see {@link exportCoverArt} - Export cover art to file
|
|
125
|
-
* @see {@link importCoverArt} - Import cover art from file
|
|
126
|
-
* @see {@link copyCoverArt} - Copy cover art between files
|
|
127
|
-
*/
|
|
128
|
-
export {
|
|
129
|
-
copyCoverArt,
|
|
130
|
-
exportAllPictures,
|
|
131
|
-
exportCoverArt,
|
|
132
|
-
exportPictureByType,
|
|
133
|
-
findCoverArtFiles,
|
|
134
|
-
importCoverArt,
|
|
135
|
-
importPictureWithType,
|
|
136
|
-
loadPictureFromFile,
|
|
137
|
-
savePictureToFile,
|
|
138
|
-
} from "./src/file-utils.ts";
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Web browser utilities for cover art operations.
|
|
142
|
-
* @see {@link pictureToDataURL} - Convert picture to data URL
|
|
143
|
-
* @see {@link setCoverArtFromCanvas} - Set cover art from HTML canvas
|
|
144
|
-
* @see {@link displayPicture} - Display picture in HTML img element
|
|
145
|
-
*/
|
|
146
|
-
export {
|
|
147
|
-
canvasToPicture,
|
|
148
|
-
createPictureDownloadURL,
|
|
149
|
-
createPictureGallery,
|
|
150
|
-
dataURLToPicture,
|
|
151
|
-
displayPicture,
|
|
152
|
-
imageFileToPicture,
|
|
153
|
-
pictureToDataURL,
|
|
154
|
-
setCoverArtFromCanvas,
|
|
155
|
-
} from "./src/web-utils.ts";
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Type exports for TypeScript users.
|
|
159
|
-
* These types define the structure of metadata, audio properties,
|
|
160
|
-
* and configuration options used throughout the library.
|
|
161
|
-
*
|
|
162
|
-
* @see {@link Tag} - Basic metadata structure
|
|
163
|
-
* @see {@link ExtendedTag} - Extended metadata with advanced fields
|
|
164
|
-
* @see {@link AudioProperties} - Audio technical properties
|
|
165
|
-
* @see {@link TagLibConfig} - Configuration options
|
|
166
|
-
*/
|
|
167
|
-
export type {
|
|
168
|
-
AudioFormat,
|
|
169
|
-
AudioProperties,
|
|
170
|
-
ExtendedTag,
|
|
171
|
-
FieldMapping,
|
|
172
|
-
FileType,
|
|
173
|
-
Picture,
|
|
174
|
-
PropertyMap,
|
|
175
|
-
Tag,
|
|
176
|
-
TagLibConfig,
|
|
177
|
-
TagName,
|
|
178
|
-
} from "./src/types.ts";
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Enum exports
|
|
182
|
-
*/
|
|
183
|
-
export { PictureType } from "./src/types.ts";
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Wasm module types for advanced usage.
|
|
187
|
-
* @see {@link TagLibModule} - Full TagLib Wasm module interface
|
|
188
|
-
* @see {@link WasmModule} - Base Emscripten module interface
|
|
189
|
-
*/
|
|
190
|
-
export type { TagLibModule, WasmModule } from "./src/wasm.ts";
|
|
191
|
-
|
|
192
|
-
// Import the type for use in this file
|
|
193
|
-
import type { TagLibModule } from "./src/wasm.ts";
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Load the TagLib Wasm module.
|
|
197
|
-
* This function initializes the WebAssembly module and returns
|
|
198
|
-
* the loaded module for use with the Core API.
|
|
199
|
-
*
|
|
200
|
-
* @returns Promise resolving to the initialized TagLib module
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```typescript
|
|
204
|
-
* import { loadTagLibModule, createTagLib } from "taglib-wasm";
|
|
205
|
-
*
|
|
206
|
-
* // Manual module loading for advanced configuration
|
|
207
|
-
* const module = await loadTagLibModule();
|
|
208
|
-
* const taglib = await createTagLib(module);
|
|
209
|
-
* ```
|
|
210
|
-
*
|
|
211
|
-
* @note Most users should use `TagLib.initialize()` instead,
|
|
212
|
-
* which handles module loading automatically.
|
|
213
|
-
*/
|
|
214
|
-
export async function loadTagLibModule(): Promise<TagLibModule> {
|
|
215
|
-
// Now that we're using ES6 modules, we can use dynamic import directly
|
|
216
|
-
const { default: createTagLibModule } = await import(
|
|
217
|
-
"./build/taglib-wrapper.js"
|
|
218
|
-
);
|
|
219
|
-
const module = await createTagLibModule();
|
|
220
|
-
return module as TagLibModule;
|
|
221
|
-
}
|