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.
Files changed (82) hide show
  1. package/README.md +22 -35
  2. package/dist/index.d.ts +10 -10
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +117 -134
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/constants.js +211 -0
  7. package/dist/src/constants.js.map +1 -0
  8. package/dist/src/errors.js +180 -0
  9. package/dist/src/errors.js.map +1 -0
  10. package/dist/src/file-utils.d.ts +2 -2
  11. package/dist/src/file-utils.d.ts.map +1 -1
  12. package/dist/src/file-utils.js +394 -0
  13. package/dist/src/file-utils.js.map +1 -0
  14. package/dist/src/mod.d.ts +4 -4
  15. package/dist/src/mod.d.ts.map +1 -1
  16. package/dist/src/mod.js +7 -0
  17. package/dist/src/mod.js.map +1 -0
  18. package/dist/src/simple.d.ts +4 -4
  19. package/dist/src/simple.d.ts.map +1 -1
  20. package/dist/src/{simple.ts → simple.js} +193 -311
  21. package/dist/src/simple.js.map +1 -0
  22. package/dist/src/taglib.d.ts +3 -3
  23. package/dist/src/taglib.d.ts.map +1 -1
  24. package/dist/src/taglib.js +516 -0
  25. package/dist/src/taglib.js.map +1 -0
  26. package/dist/src/types.d.ts +2 -2
  27. package/dist/src/types.d.ts.map +1 -1
  28. package/dist/src/types.js +239 -0
  29. package/dist/src/types.js.map +1 -0
  30. package/dist/src/utils/file.js +65 -0
  31. package/dist/src/utils/file.js.map +1 -0
  32. package/dist/src/utils/write.js +49 -0
  33. package/dist/src/utils/write.js.map +1 -0
  34. package/dist/src/wasm-workers.d.ts +1 -1
  35. package/dist/src/wasm-workers.d.ts.map +1 -1
  36. package/dist/src/wasm-workers.js +148 -0
  37. package/dist/src/wasm-workers.js.map +1 -0
  38. package/dist/src/wasm.js +6 -0
  39. package/dist/src/wasm.js.map +1 -0
  40. package/dist/src/web-utils.d.ts +2 -2
  41. package/dist/src/web-utils.d.ts.map +1 -1
  42. package/{src/web-utils.ts → dist/src/web-utils.js} +102 -184
  43. package/dist/src/web-utils.js.map +1 -0
  44. package/dist/src/workers.d.ts +2 -2
  45. package/dist/src/workers.d.ts.map +1 -1
  46. package/dist/src/workers.js +389 -0
  47. package/dist/src/workers.js.map +1 -0
  48. package/dist/taglib-wrapper.js +8 -2528
  49. package/package.json +7 -10
  50. package/dist/index.ts +0 -221
  51. package/dist/src/constants.ts +0 -227
  52. package/dist/src/errors.ts +0 -254
  53. package/dist/src/file-utils.ts +0 -483
  54. package/dist/src/file.js +0 -52
  55. package/dist/src/global.d.ts +0 -12
  56. package/dist/src/mod.ts +0 -19
  57. package/dist/src/taglib.ts +0 -961
  58. package/dist/src/types.ts +0 -538
  59. package/dist/src/utils/file.ts +0 -86
  60. package/dist/src/utils/write.ts +0 -66
  61. package/dist/src/wasm-workers.ts +0 -176
  62. package/dist/src/wasm.ts +0 -133
  63. package/dist/src/web-utils.ts +0 -347
  64. package/dist/src/workers.ts +0 -461
  65. package/dist/src/write.js +0 -33
  66. package/index.ts +0 -221
  67. package/lib/taglib/COPYING.LGPL +0 -502
  68. package/lib/taglib/COPYING.MPL +0 -470
  69. package/lib/taglib/README.md +0 -24
  70. package/src/constants.ts +0 -227
  71. package/src/errors.ts +0 -254
  72. package/src/file-utils.ts +0 -483
  73. package/src/global.d.ts +0 -12
  74. package/src/mod.ts +0 -19
  75. package/src/simple.ts +0 -667
  76. package/src/taglib.ts +0 -961
  77. package/src/types.ts +0 -538
  78. package/src/utils/file.ts +0 -86
  79. package/src/utils/write.ts +0 -66
  80. package/src/wasm-workers.ts +0 -176
  81. package/src/wasm.ts +0 -133
  82. package/src/workers.ts +0 -461
@@ -1,483 +0,0 @@
1
- /**
2
- * @fileoverview File I/O utilities for working with cover art in taglib-wasm
3
- *
4
- * This module provides file system helpers for saving and loading cover art
5
- * in Node.js, Deno, and Bun environments.
6
- *
7
- * @example
8
- * ```typescript
9
- * import { exportCoverArt, importCoverArt } from "taglib-wasm/file-utils";
10
- *
11
- * // Export cover art from audio file to image file
12
- * await exportCoverArt("song.mp3", "cover.jpg");
13
- *
14
- * // Import cover art from image file to audio file
15
- * await importCoverArt("song.mp3", "new-cover.png");
16
- * ```
17
- */
18
-
19
- import type { Picture } from "./types.ts";
20
- import { PictureType } from "./types.ts";
21
- import {
22
- applyPictures,
23
- getCoverArt,
24
- readPictures,
25
- replacePictureByType,
26
- setCoverArt,
27
- } from "./simple.ts";
28
- import { readFileData } from "./utils/file.ts";
29
- import { writeFileData } from "./utils/write.ts";
30
-
31
- /**
32
- * Export cover art from an audio file to an image file
33
- *
34
- * Extracts the primary cover art (front cover if available, otherwise first picture)
35
- * and saves it to the specified path.
36
- *
37
- * @param audioPath - Path to the audio file
38
- * @param imagePath - Path where the image should be saved
39
- * @returns Promise that resolves when the image is saved
40
- * @throws Error if no cover art is found
41
- *
42
- * @example
43
- * ```typescript
44
- * // Export cover art as JPEG
45
- * await exportCoverArt("album/track01.mp3", "album/cover.jpg");
46
- * ```
47
- */
48
- export async function exportCoverArt(
49
- audioPath: string,
50
- imagePath: string,
51
- ): Promise<void> {
52
- const coverData = await getCoverArt(audioPath);
53
- if (!coverData) {
54
- throw new Error(`No cover art found in: ${audioPath}`);
55
- }
56
-
57
- await writeFileData(imagePath, coverData);
58
- }
59
-
60
- /**
61
- * Export a specific picture type from an audio file
62
- *
63
- * @param audioPath - Path to the audio file
64
- * @param imagePath - Path where the image should be saved
65
- * @param type - Picture type to export
66
- * @returns Promise that resolves when the image is saved
67
- * @throws Error if no picture of the specified type is found
68
- *
69
- * @example
70
- * ```typescript
71
- * // Export back cover
72
- * await exportPictureByType(
73
- * "album/track01.mp3",
74
- * "album/back-cover.jpg",
75
- * PictureType.BackCover
76
- * );
77
- * ```
78
- */
79
- export async function exportPictureByType(
80
- audioPath: string,
81
- imagePath: string,
82
- type: PictureType,
83
- ): Promise<void> {
84
- const pictures = await readPictures(audioPath);
85
- const picture = pictures.find((pic) => pic.type === type);
86
-
87
- if (!picture) {
88
- throw new Error(`No picture of type ${type} found in: ${audioPath}`);
89
- }
90
-
91
- await writeFileData(imagePath, picture.data);
92
- }
93
-
94
- /**
95
- * Export all pictures from an audio file
96
- *
97
- * Saves each picture with a numbered suffix based on its type and index.
98
- *
99
- * @param audioPath - Path to the audio file
100
- * @param outputDir - Directory where images should be saved
101
- * @param options - Export options
102
- * @returns Promise resolving to array of created file paths
103
- *
104
- * @example
105
- * ```typescript
106
- * // Export all pictures to a directory
107
- * const files = await exportAllPictures("song.mp3", "./artwork/");
108
- * console.log(`Exported ${files.length} pictures`);
109
- * ```
110
- */
111
- export async function exportAllPictures(
112
- audioPath: string,
113
- outputDir: string,
114
- options: {
115
- nameFormat?: (picture: Picture, index: number) => string;
116
- } = {},
117
- ): Promise<string[]> {
118
- const pictures = await readPictures(audioPath);
119
- const exportedPaths: string[] = [];
120
-
121
- // Ensure directory ends with separator
122
- const dir = outputDir.endsWith("/") ? outputDir : outputDir + "/";
123
-
124
- for (let i = 0; i < pictures.length; i++) {
125
- const picture = pictures[i];
126
-
127
- // Determine filename
128
- let filename: string;
129
- if (options.nameFormat) {
130
- filename = options.nameFormat(picture, i);
131
- } else {
132
- // Default naming: type-index.ext
133
- const typeNames: Record<number, string> = {
134
- [PictureType.FrontCover]: "front-cover",
135
- [PictureType.BackCover]: "back-cover",
136
- [PictureType.LeafletPage]: "leaflet",
137
- [PictureType.Media]: "media",
138
- [PictureType.LeadArtist]: "lead-artist",
139
- [PictureType.Artist]: "artist",
140
- [PictureType.Conductor]: "conductor",
141
- [PictureType.Band]: "band",
142
- [PictureType.Composer]: "composer",
143
- [PictureType.Lyricist]: "lyricist",
144
- [PictureType.RecordingLocation]: "recording-location",
145
- [PictureType.DuringRecording]: "during-recording",
146
- [PictureType.DuringPerformance]: "during-performance",
147
- [PictureType.MovieScreenCapture]: "screen-capture",
148
- [PictureType.ColouredFish]: "fish",
149
- [PictureType.Illustration]: "illustration",
150
- [PictureType.BandLogo]: "band-logo",
151
- [PictureType.PublisherLogo]: "publisher-logo",
152
- };
153
-
154
- const typeName = typeNames[picture.type] || "other";
155
- const ext = picture.mimeType.split("/")[1] || "jpg";
156
- filename = `${typeName}-${i + 1}.${ext}`;
157
- }
158
-
159
- const fullPath = dir + filename;
160
- await writeFileData(fullPath, picture.data);
161
- exportedPaths.push(fullPath);
162
- }
163
-
164
- return exportedPaths;
165
- }
166
-
167
- /**
168
- * Import cover art from an image file to an audio file
169
- *
170
- * Replaces all existing pictures with a single front cover from the image file.
171
- * The audio file is modified in place.
172
- *
173
- * @param audioPath - Path to the audio file to update
174
- * @param imagePath - Path to the image file to import
175
- * @param options - Import options
176
- * @returns Promise that resolves when the audio file is updated
177
- *
178
- * @example
179
- * ```typescript
180
- * // Replace cover art with a new image
181
- * await importCoverArt("song.mp3", "new-cover.jpg");
182
- * ```
183
- */
184
- export async function importCoverArt(
185
- audioPath: string,
186
- imagePath: string,
187
- options: {
188
- mimeType?: string;
189
- description?: string;
190
- } = {},
191
- ): Promise<void> {
192
- const imageData = await readFileData(imagePath);
193
-
194
- // Detect MIME type from file extension if not provided
195
- let mimeType = options.mimeType;
196
- if (!mimeType) {
197
- const ext = imagePath.split(".").pop()?.toLowerCase();
198
- const mimeTypes: Record<string, string> = {
199
- "jpg": "image/jpeg",
200
- "jpeg": "image/jpeg",
201
- "png": "image/png",
202
- "gif": "image/gif",
203
- "webp": "image/webp",
204
- "bmp": "image/bmp",
205
- };
206
- mimeType = mimeTypes[ext || ""] || "image/jpeg";
207
- }
208
-
209
- const modifiedBuffer = await setCoverArt(audioPath, imageData, mimeType);
210
- await writeFileData(audioPath, modifiedBuffer);
211
- }
212
-
213
- /**
214
- * Import a picture from file with specific type
215
- *
216
- * Adds or replaces a picture of the specified type in the audio file.
217
- * The audio file is modified in place.
218
- *
219
- * @param audioPath - Path to the audio file to update
220
- * @param imagePath - Path to the image file to import
221
- * @param type - Picture type to set
222
- * @param options - Import options
223
- * @returns Promise that resolves when the audio file is updated
224
- *
225
- * @example
226
- * ```typescript
227
- * // Add a back cover
228
- * await importPictureWithType(
229
- * "song.mp3",
230
- * "back-cover.jpg",
231
- * PictureType.BackCover,
232
- * { description: "Album back cover" }
233
- * );
234
- * ```
235
- */
236
- export async function importPictureWithType(
237
- audioPath: string,
238
- imagePath: string,
239
- type: PictureType,
240
- options: {
241
- mimeType?: string;
242
- description?: string;
243
- } = {},
244
- ): Promise<void> {
245
- const imageData = await readFileData(imagePath);
246
-
247
- // Detect MIME type from file extension if not provided
248
- let mimeType = options.mimeType;
249
- if (!mimeType) {
250
- const ext = imagePath.split(".").pop()?.toLowerCase();
251
- const mimeTypes: Record<string, string> = {
252
- "jpg": "image/jpeg",
253
- "jpeg": "image/jpeg",
254
- "png": "image/png",
255
- "gif": "image/gif",
256
- "webp": "image/webp",
257
- "bmp": "image/bmp",
258
- };
259
- mimeType = mimeTypes[ext || ""] || "image/jpeg";
260
- }
261
-
262
- const picture: Picture = {
263
- mimeType,
264
- data: imageData,
265
- type,
266
- description: options.description,
267
- };
268
-
269
- const modifiedBuffer = await replacePictureByType(audioPath, picture);
270
- await writeFileData(audioPath, modifiedBuffer);
271
- }
272
-
273
- /**
274
- * Load a picture from an image file
275
- *
276
- * @param imagePath - Path to the image file
277
- * @param type - Picture type (defaults to FrontCover)
278
- * @param options - Picture options
279
- * @returns Picture object ready to be applied to audio files
280
- *
281
- * @example
282
- * ```typescript
283
- * const frontCover = await loadPictureFromFile("cover.jpg");
284
- * const backCover = await loadPictureFromFile("back.png", PictureType.BackCover);
285
- *
286
- * const modifiedBuffer = await applyPictures("song.mp3", [frontCover, backCover]);
287
- * ```
288
- */
289
- export async function loadPictureFromFile(
290
- imagePath: string,
291
- type: PictureType = PictureType.FrontCover,
292
- options: {
293
- mimeType?: string;
294
- description?: string;
295
- } = {},
296
- ): Promise<Picture> {
297
- const data = await readFileData(imagePath);
298
-
299
- // Detect MIME type from file extension if not provided
300
- let mimeType = options.mimeType;
301
- if (!mimeType) {
302
- const ext = imagePath.split(".").pop()?.toLowerCase();
303
- const mimeTypes: Record<string, string> = {
304
- "jpg": "image/jpeg",
305
- "jpeg": "image/jpeg",
306
- "png": "image/png",
307
- "gif": "image/gif",
308
- "webp": "image/webp",
309
- "bmp": "image/bmp",
310
- };
311
- mimeType = mimeTypes[ext || ""] || "image/jpeg";
312
- }
313
-
314
- return {
315
- mimeType,
316
- data,
317
- type,
318
- description: options.description || imagePath.split("/").pop(),
319
- };
320
- }
321
-
322
- /**
323
- * Save a picture to an image file
324
- *
325
- * @param picture - Picture object to save
326
- * @param imagePath - Path where the image should be saved
327
- * @returns Promise that resolves when the image is saved
328
- *
329
- * @example
330
- * ```typescript
331
- * const pictures = await readPictures("song.mp3");
332
- * for (const picture of pictures) {
333
- * await savePictureToFile(picture, `export-${picture.type}.jpg`);
334
- * }
335
- * ```
336
- */
337
- export async function savePictureToFile(
338
- picture: Picture,
339
- imagePath: string,
340
- ): Promise<void> {
341
- await writeFileData(imagePath, picture.data);
342
- }
343
-
344
- /**
345
- * Copy cover art from one audio file to another
346
- *
347
- * @param sourcePath - Path to source audio file
348
- * @param targetPath - Path to target audio file (modified in place)
349
- * @param options - Copy options
350
- * @returns Promise that resolves when cover art is copied
351
- * @throws Error if source has no cover art
352
- *
353
- * @example
354
- * ```typescript
355
- * // Copy cover art from one file to another
356
- * await copyCoverArt("album/track01.mp3", "album/track02.mp3");
357
- *
358
- * // Copy all pictures
359
- * await copyCoverArt("source.mp3", "target.mp3", { copyAll: true });
360
- * ```
361
- */
362
- export async function copyCoverArt(
363
- sourcePath: string,
364
- targetPath: string,
365
- options: {
366
- copyAll?: boolean;
367
- } = {},
368
- ): Promise<void> {
369
- if (options.copyAll) {
370
- // Copy all pictures
371
- const pictures = await readPictures(sourcePath);
372
- if (pictures.length === 0) {
373
- throw new Error(`No pictures found in: ${sourcePath}`);
374
- }
375
- const modifiedBuffer = await applyPictures(targetPath, pictures);
376
- await writeFileData(targetPath, modifiedBuffer);
377
- } else {
378
- // Copy just the primary cover art
379
- const coverData = await getCoverArt(sourcePath);
380
- if (!coverData) {
381
- throw new Error(`No cover art found in: ${sourcePath}`);
382
- }
383
-
384
- // Find the MIME type from the source
385
- const pictures = await readPictures(sourcePath);
386
- const coverPicture = pictures.find((p) =>
387
- p.type === PictureType.FrontCover
388
- ) || pictures[0];
389
-
390
- const modifiedBuffer = await setCoverArt(
391
- targetPath,
392
- coverData,
393
- coverPicture.mimeType,
394
- );
395
- await writeFileData(targetPath, modifiedBuffer);
396
- }
397
- }
398
-
399
- /**
400
- * Check if cover art files exist for an audio file
401
- *
402
- * Looks for common cover art filenames in the same directory as the audio file.
403
- *
404
- * @param audioPath - Path to the audio file
405
- * @returns Object with found cover art paths
406
- *
407
- * @example
408
- * ```typescript
409
- * const covers = await findCoverArtFiles("music/album/track01.mp3");
410
- * if (covers.front) {
411
- * await importCoverArt("music/album/track01.mp3", covers.front);
412
- * }
413
- * ```
414
- */
415
- export async function findCoverArtFiles(
416
- audioPath: string,
417
- ): Promise<{
418
- front?: string;
419
- back?: string;
420
- folder?: string;
421
- [key: string]: string | undefined;
422
- }> {
423
- const dir = audioPath.substring(0, audioPath.lastIndexOf("/") + 1);
424
- const commonNames = [
425
- "cover",
426
- "front",
427
- "folder",
428
- "album",
429
- "artwork",
430
- "Cover",
431
- "Front",
432
- "Folder",
433
- "Album",
434
- "Artwork",
435
- ];
436
- const extensions = ["jpg", "jpeg", "png", "gif", "webp"];
437
- const found: Record<string, string> = {};
438
-
439
- // Check for common front cover names
440
- for (const name of commonNames) {
441
- for (const ext of extensions) {
442
- const path = `${dir}${name}.${ext}`;
443
- try {
444
- // Try to read a single byte to check if file exists
445
- const data = await readFileData(path);
446
- if (data.length > 0) {
447
- if (
448
- !found.front && ["cover", "front", "Cover", "Front"].includes(name)
449
- ) {
450
- found.front = path;
451
- } else if (!found.folder && ["folder", "Folder"].includes(name)) {
452
- found.folder = path;
453
- } else {
454
- found[name.toLowerCase()] = path;
455
- }
456
- break; // Found this name, skip other extensions
457
- }
458
- } catch {
459
- // File doesn't exist, continue
460
- }
461
- }
462
- }
463
-
464
- // Check for back cover
465
- const backNames = ["back", "Back", "back-cover", "Back-Cover"];
466
- for (const name of backNames) {
467
- for (const ext of extensions) {
468
- const path = `${dir}${name}.${ext}`;
469
- try {
470
- const data = await readFileData(path);
471
- if (data.length > 0) {
472
- found.back = path;
473
- break;
474
- }
475
- } catch {
476
- // File doesn't exist, continue
477
- }
478
- }
479
- if (found.back) break;
480
- }
481
-
482
- return found;
483
- }
package/dist/src/file.js DELETED
@@ -1,52 +0,0 @@
1
- import { EnvironmentError, FileOperationError } from "../errors.ts";
2
- async function readFileData(file) {
3
- if (file instanceof Uint8Array) {
4
- return file;
5
- }
6
- if (file instanceof ArrayBuffer) {
7
- return new Uint8Array(file);
8
- }
9
- if (typeof File !== "undefined" && file instanceof File) {
10
- return new Uint8Array(await file.arrayBuffer());
11
- }
12
- if (typeof file === "string") {
13
- const hasDeno = typeof globalThis.Deno !== "undefined";
14
- const hasNode = typeof globalThis.process !== "undefined" && globalThis.process.versions && globalThis.process.versions.node;
15
- const hasBun = typeof globalThis.Bun !== "undefined";
16
- if (!hasDeno && !hasNode && !hasBun) {
17
- const env = "Browser";
18
- throw new EnvironmentError(
19
- env,
20
- "does not support file path reading",
21
- "filesystem access"
22
- );
23
- }
24
- try {
25
- if (hasDeno) {
26
- return await globalThis.Deno.readFile(file);
27
- }
28
- if (hasNode) {
29
- const { readFile } = await import("fs/promises");
30
- return new Uint8Array(await readFile(file));
31
- }
32
- if (hasBun) {
33
- const bunFile = globalThis.Bun.file(file);
34
- return new Uint8Array(await bunFile.arrayBuffer());
35
- }
36
- } catch (error) {
37
- throw new FileOperationError(
38
- "read",
39
- error.message,
40
- file
41
- );
42
- }
43
- }
44
- const inputType = Object.prototype.toString.call(file);
45
- throw new FileOperationError(
46
- "read",
47
- `Invalid file input type: ${inputType}. Expected string path, Uint8Array, ArrayBuffer, or File object.`
48
- );
49
- }
50
- export {
51
- readFileData
52
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * Global type declarations for cross-runtime compatibility
3
- */
4
-
5
- // Declare Deno global for TypeScript when not in Deno environment
6
- declare global {
7
- // Only declare if not already defined by Deno runtime
8
- // @ts-ignore: Suppress duplicate identifier error in Deno
9
- const Deno: any;
10
- }
11
-
12
- export {};
package/dist/src/mod.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * @fileoverview TagLib WebAssembly TypeScript bindings
3
- * Universal audio metadata handling for Deno, Node.js, and browsers
4
- */
5
-
6
- // Export from taglib.ts
7
- export { AudioFileImpl, createTagLib, TagLib } from "./taglib.ts";
8
- export type { AudioFile, Tag } from "./taglib.ts"; // Export the interfaces
9
-
10
- // Export from types.ts (except Tag to avoid conflict)
11
- export type {
12
- AudioProperties,
13
- FileType,
14
- PropertyMap,
15
- Tag as BasicTag, // Rename the basic Tag interface to avoid conflict
16
- } from "./types.ts";
17
-
18
- // Export from wasm.ts
19
- export type { TagLibModule } from "./wasm.ts";