taglib-wasm 0.3.3 → 0.3.9
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/CONTRIBUTING.md +293 -0
- package/NOTICE +34 -0
- package/README.md +122 -511
- package/dist/index.d.ts +132 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +137 -0
- package/dist/index.ts +220 -0
- package/dist/src/constants.d.ts +201 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.ts +227 -0
- package/dist/src/errors.d.ts +89 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.ts +237 -0
- package/dist/src/file-utils.d.ts +205 -0
- package/dist/src/file-utils.d.ts.map +1 -0
- package/dist/src/file-utils.ts +467 -0
- package/dist/src/file.js +47 -0
- package/dist/src/global.d.ts +10 -0
- package/dist/src/mod.d.ts +9 -0
- package/dist/src/mod.d.ts.map +1 -0
- package/dist/src/mod.ts +19 -0
- package/dist/src/simple.d.ts +347 -0
- package/dist/src/simple.d.ts.map +1 -0
- package/dist/src/simple.ts +659 -0
- package/dist/src/taglib.d.ts +502 -0
- package/dist/src/taglib.d.ts.map +1 -0
- package/dist/src/taglib.ts +959 -0
- package/dist/src/types.d.ts +323 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.ts +538 -0
- package/dist/src/utils/file.d.ts +15 -0
- package/dist/src/utils/file.d.ts.map +1 -0
- package/dist/src/utils/file.ts +82 -0
- package/dist/src/utils/write.d.ts +15 -0
- package/dist/src/utils/write.d.ts.map +1 -0
- package/dist/src/utils/write.ts +61 -0
- package/dist/src/wasm-workers.d.ts +33 -0
- package/dist/src/wasm-workers.d.ts.map +1 -0
- package/dist/src/wasm-workers.ts +176 -0
- package/dist/src/wasm.d.ts +97 -0
- package/dist/src/wasm.d.ts.map +1 -0
- package/dist/src/wasm.ts +133 -0
- package/dist/src/web-utils.d.ts +180 -0
- package/dist/src/web-utils.d.ts.map +1 -0
- package/dist/src/web-utils.ts +347 -0
- package/dist/src/workers.d.ts +219 -0
- package/dist/src/workers.d.ts.map +1 -0
- package/dist/src/workers.ts +465 -0
- package/dist/src/write.js +33 -0
- package/dist/taglib-wrapper.d.ts +5 -0
- package/dist/taglib-wrapper.js +14 -0
- package/dist/taglib.wasm +0 -0
- package/index.ts +100 -7
- package/package.json +40 -16
- package/src/errors.ts +237 -0
- package/src/file-utils.ts +467 -0
- package/src/global.d.ts +10 -0
- package/src/simple.ts +399 -84
- package/src/taglib.ts +522 -28
- package/src/types.ts +1 -1
- package/src/utils/file.ts +82 -0
- package/src/utils/write.ts +61 -0
- package/src/wasm-workers.ts +13 -4
- package/src/wasm.ts +1 -1
- package/src/web-utils.ts +347 -0
- package/src/workers.ts +32 -13
- package/build/taglib.js +0 -2407
- package/build/taglib.wasm +0 -0
package/dist/src/file.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
try {
|
|
14
|
+
if (typeof Deno !== "undefined") {
|
|
15
|
+
return await Deno.readFile(file);
|
|
16
|
+
}
|
|
17
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
18
|
+
const { readFile } = await import("fs/promises");
|
|
19
|
+
return new Uint8Array(await readFile(file));
|
|
20
|
+
}
|
|
21
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
22
|
+
const bunFile = globalThis.Bun.file(file);
|
|
23
|
+
return new Uint8Array(await bunFile.arrayBuffer());
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new FileOperationError(
|
|
27
|
+
"read",
|
|
28
|
+
error.message,
|
|
29
|
+
file
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const env = typeof Deno !== "undefined" ? "Deno" : typeof process !== "undefined" ? "Node.js" : typeof globalThis.Bun !== "undefined" ? "Bun" : "Browser";
|
|
33
|
+
throw new EnvironmentError(
|
|
34
|
+
env,
|
|
35
|
+
"does not support file path reading",
|
|
36
|
+
"filesystem access"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const inputType = Object.prototype.toString.call(file);
|
|
40
|
+
throw new FileOperationError(
|
|
41
|
+
"read",
|
|
42
|
+
`Invalid file input type: ${inputType}. Expected string path, Uint8Array, ArrayBuffer, or File object.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
readFileData
|
|
47
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TagLib WebAssembly TypeScript bindings
|
|
3
|
+
* Universal audio metadata handling for Deno, Node.js, and browsers
|
|
4
|
+
*/
|
|
5
|
+
export { AudioFileImpl, createTagLib, TagLib } from "./taglib.ts";
|
|
6
|
+
export type { AudioFile, Tag } from "./taglib.ts";
|
|
7
|
+
export type { AudioProperties, FileType, PropertyMap, Tag as BasicTag, } from "./types.ts";
|
|
8
|
+
export type { TagLibModule } from "./wasm.ts";
|
|
9
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAClE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlD,YAAY,EACV,eAAe,EACf,QAAQ,EACR,WAAW,EACX,GAAG,IAAI,QAAQ,GAChB,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/src/mod.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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";
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Simplified API for taglib-wasm matching go-taglib's interface
|
|
3
|
+
*
|
|
4
|
+
* This module provides a dead-simple API for reading and writing audio metadata,
|
|
5
|
+
* inspired by go-taglib's excellent developer experience.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { readTags, writeTags, readProperties } from "taglib-wasm/simple";
|
|
10
|
+
*
|
|
11
|
+
* // Read tags
|
|
12
|
+
* const tags = await readTags("song.mp3");
|
|
13
|
+
* console.log(tags.album);
|
|
14
|
+
*
|
|
15
|
+
* // Write tags
|
|
16
|
+
* await writeTags("song.mp3", {
|
|
17
|
+
* album: "New Album",
|
|
18
|
+
* artist: "New Artist"
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Read audio properties
|
|
22
|
+
* const props = await readProperties("song.mp3");
|
|
23
|
+
* console.log(`Duration: ${props.length}s, Bitrate: ${props.bitrate}kbps`);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import type { AudioProperties, Tag, Picture } from "./types.ts";
|
|
27
|
+
import { PictureType } from "./types.ts";
|
|
28
|
+
/**
|
|
29
|
+
* Read metadata tags from an audio file
|
|
30
|
+
*
|
|
31
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
32
|
+
* @returns Object containing all metadata tags
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const tags = await readTags("song.mp3");
|
|
37
|
+
* console.log(tags.title, tags.artist, tags.album);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function readTags(file: string | Uint8Array | ArrayBuffer | File): Promise<Tag>;
|
|
41
|
+
/**
|
|
42
|
+
* Apply metadata tags to an audio file and return the modified buffer
|
|
43
|
+
*
|
|
44
|
+
* This function loads the file, applies the tag changes, and returns
|
|
45
|
+
* the modified file as a buffer. The original file is not modified.
|
|
46
|
+
*
|
|
47
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
48
|
+
* @param tags - Object containing tags to apply (undefined values are ignored)
|
|
49
|
+
* @param options - Write options (currently unused, for go-taglib compatibility)
|
|
50
|
+
* @returns Modified file buffer with new tags applied
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const modifiedBuffer = await applyTags("song.mp3", {
|
|
55
|
+
* title: "New Title",
|
|
56
|
+
* artist: "New Artist",
|
|
57
|
+
* album: "New Album",
|
|
58
|
+
* year: 2025
|
|
59
|
+
* });
|
|
60
|
+
* // Save modifiedBuffer to file or use as needed
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function applyTags(file: string | Uint8Array | ArrayBuffer | File, tags: Partial<Tag>, options?: number): Promise<Uint8Array>;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Use `applyTags` instead. This alias will be removed in v1.0.0.
|
|
66
|
+
*/
|
|
67
|
+
export declare const writeTags: typeof applyTags;
|
|
68
|
+
/**
|
|
69
|
+
* Update metadata tags in an audio file and save to disk
|
|
70
|
+
*
|
|
71
|
+
* This function modifies the file on disk by applying the specified tags
|
|
72
|
+
* and writing the changes back to the original file path.
|
|
73
|
+
*
|
|
74
|
+
* @param file - File path as a string (required for disk operations)
|
|
75
|
+
* @param tags - Object containing tags to write (undefined values are ignored)
|
|
76
|
+
* @param options - Write options (currently unused, for go-taglib compatibility)
|
|
77
|
+
* @throws {InvalidInputError} If file is not a string
|
|
78
|
+
* @throws {FileOperationError} If file write fails
|
|
79
|
+
* @returns Promise that resolves when the file has been updated on disk
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Update tags and save to disk
|
|
84
|
+
* await updateTags("song.mp3", {
|
|
85
|
+
* title: "New Title",
|
|
86
|
+
* artist: "New Artist"
|
|
87
|
+
* });
|
|
88
|
+
* // File on disk now has updated tags
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @see applyTags - For getting a modified buffer without writing to disk
|
|
92
|
+
*/
|
|
93
|
+
export declare function updateTags(file: string, tags: Partial<Tag>, options?: number): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Read audio properties from a file
|
|
96
|
+
*
|
|
97
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
98
|
+
* @returns Audio properties including duration, bitrate, sample rate, etc.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const props = await readProperties("song.mp3");
|
|
103
|
+
* console.log(`Duration: ${props.length} seconds`);
|
|
104
|
+
* console.log(`Bitrate: ${props.bitrate} kbps`);
|
|
105
|
+
* console.log(`Sample rate: ${props.sampleRate} Hz`);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function readProperties(file: string | Uint8Array | ArrayBuffer | File): Promise<AudioProperties>;
|
|
109
|
+
/**
|
|
110
|
+
* Tag field constants for go-taglib compatibility.
|
|
111
|
+
* These match the constants used in go-taglib for consistent API.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { Title, Artist, Album } from "taglib-wasm/simple";
|
|
116
|
+
*
|
|
117
|
+
* const tags = await readTags("song.mp3");
|
|
118
|
+
* console.log(tags[Title]); // Same as tags.title
|
|
119
|
+
* console.log(tags[Artist]); // Same as tags.artist
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare const Title = "title";
|
|
123
|
+
export declare const Artist = "artist";
|
|
124
|
+
export declare const Album = "album";
|
|
125
|
+
export declare const Comment = "comment";
|
|
126
|
+
export declare const Genre = "genre";
|
|
127
|
+
export declare const Year = "year";
|
|
128
|
+
export declare const Track = "track";
|
|
129
|
+
export declare const AlbumArtist = "albumartist";
|
|
130
|
+
export declare const Composer = "composer";
|
|
131
|
+
export declare const DiscNumber = "discnumber";
|
|
132
|
+
/**
|
|
133
|
+
* Check if a file is a valid audio file
|
|
134
|
+
*
|
|
135
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
136
|
+
* @returns true if the file is a valid audio file
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* if (await isValidAudioFile("maybe-audio.bin")) {
|
|
141
|
+
* const tags = await readTags("maybe-audio.bin");
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function isValidAudioFile(file: string | Uint8Array | ArrayBuffer | File): Promise<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* Get the audio format of a file
|
|
148
|
+
*
|
|
149
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
150
|
+
* @returns Audio format string (e.g., "MP3", "FLAC", "OGG") or undefined
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const format = await getFormat("song.mp3");
|
|
155
|
+
* console.log(`File format: ${format}`); // "MP3"
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function getFormat(file: string | Uint8Array | ArrayBuffer | File): Promise<string | undefined>;
|
|
159
|
+
/**
|
|
160
|
+
* Clear all tags from a file
|
|
161
|
+
*
|
|
162
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
163
|
+
* @returns Modified file buffer with tags removed
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const cleanBuffer = await clearTags("song.mp3");
|
|
168
|
+
* // Save cleanBuffer to remove all metadata
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export declare function clearTags(file: string | Uint8Array | ArrayBuffer | File): Promise<Uint8Array>;
|
|
172
|
+
/**
|
|
173
|
+
* Read cover art/pictures from an audio file
|
|
174
|
+
*
|
|
175
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
176
|
+
* @returns Array of Picture objects containing cover art
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const pictures = await readPictures("song.mp3");
|
|
181
|
+
* for (const pic of pictures) {
|
|
182
|
+
* console.log(`Type: ${pic.type}, MIME: ${pic.mimeType}, Size: ${pic.data.length}`);
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare function readPictures(file: string | Uint8Array | ArrayBuffer | File): Promise<Picture[]>;
|
|
187
|
+
/**
|
|
188
|
+
* Apply pictures/cover art to an audio file and return the modified buffer
|
|
189
|
+
*
|
|
190
|
+
* This function loads the file, replaces all existing pictures with the new ones,
|
|
191
|
+
* and returns the modified file as a buffer. The original file is not modified.
|
|
192
|
+
*
|
|
193
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
194
|
+
* @param pictures - Array of Picture objects to set (replaces all existing)
|
|
195
|
+
* @returns Modified file buffer with new pictures applied
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const coverArt = {
|
|
200
|
+
* mimeType: "image/jpeg",
|
|
201
|
+
* data: jpegData, // Uint8Array
|
|
202
|
+
* type: PictureType.FrontCover,
|
|
203
|
+
* description: "Album cover"
|
|
204
|
+
* };
|
|
205
|
+
* const modifiedBuffer = await applyPictures("song.mp3", [coverArt]);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function applyPictures(file: string | Uint8Array | ArrayBuffer | File, pictures: Picture[]): Promise<Uint8Array>;
|
|
209
|
+
/**
|
|
210
|
+
* Add a single picture to an audio file and return the modified buffer
|
|
211
|
+
*
|
|
212
|
+
* This function loads the file, adds the picture to existing ones,
|
|
213
|
+
* and returns the modified file as a buffer. The original file is not modified.
|
|
214
|
+
*
|
|
215
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
216
|
+
* @param picture - Picture object to add
|
|
217
|
+
* @returns Modified file buffer with picture added
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const backCover = {
|
|
222
|
+
* mimeType: "image/png",
|
|
223
|
+
* data: pngData, // Uint8Array
|
|
224
|
+
* type: PictureType.BackCover,
|
|
225
|
+
* description: "Back cover"
|
|
226
|
+
* };
|
|
227
|
+
* const modifiedBuffer = await addPicture("song.mp3", backCover);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare function addPicture(file: string | Uint8Array | ArrayBuffer | File, picture: Picture): Promise<Uint8Array>;
|
|
231
|
+
/**
|
|
232
|
+
* Clear all pictures from a file
|
|
233
|
+
*
|
|
234
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
235
|
+
* @returns Modified file buffer with pictures removed
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* const cleanBuffer = await clearPictures("song.mp3");
|
|
240
|
+
* // Save cleanBuffer to remove all cover art
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
export declare function clearPictures(file: string | Uint8Array | ArrayBuffer | File): Promise<Uint8Array>;
|
|
244
|
+
/**
|
|
245
|
+
* Get the primary cover art from an audio file
|
|
246
|
+
*
|
|
247
|
+
* Returns the front cover if available, otherwise the first picture found.
|
|
248
|
+
* Returns null if no pictures are present.
|
|
249
|
+
*
|
|
250
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
251
|
+
* @returns Primary cover art data or null
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const coverArt = await getCoverArt("song.mp3");
|
|
256
|
+
* if (coverArt) {
|
|
257
|
+
* console.log(`Cover art size: ${coverArt.length} bytes`);
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export declare function getCoverArt(file: string | Uint8Array | ArrayBuffer | File): Promise<Uint8Array | null>;
|
|
262
|
+
/**
|
|
263
|
+
* Set the primary cover art for an audio file
|
|
264
|
+
*
|
|
265
|
+
* Replaces all existing pictures with a single front cover image.
|
|
266
|
+
*
|
|
267
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
268
|
+
* @param imageData - Image data as Uint8Array
|
|
269
|
+
* @param mimeType - MIME type of the image (e.g., "image/jpeg", "image/png")
|
|
270
|
+
* @returns Modified file buffer with cover art set
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const jpegData = await Deno.readFile("cover.jpg");
|
|
275
|
+
* const modifiedBuffer = await setCoverArt("song.mp3", jpegData, "image/jpeg");
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export declare function setCoverArt(file: string | Uint8Array | ArrayBuffer | File, imageData: Uint8Array, mimeType: string): Promise<Uint8Array>;
|
|
279
|
+
/**
|
|
280
|
+
* Find a picture by its type
|
|
281
|
+
*
|
|
282
|
+
* @param pictures - Array of pictures to search
|
|
283
|
+
* @param type - Picture type to find
|
|
284
|
+
* @returns Picture matching the type or null
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const pictures = await readPictures("song.mp3");
|
|
289
|
+
* const backCover = findPictureByType(pictures, PictureType.BackCover);
|
|
290
|
+
* if (backCover) {
|
|
291
|
+
* console.log("Found back cover art");
|
|
292
|
+
* }
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
export declare function findPictureByType(pictures: Picture[], type: PictureType): Picture | null;
|
|
296
|
+
/**
|
|
297
|
+
* Replace or add a picture of a specific type
|
|
298
|
+
*
|
|
299
|
+
* If a picture of the given type already exists, it will be replaced.
|
|
300
|
+
* Otherwise, the new picture will be added to the existing ones.
|
|
301
|
+
*
|
|
302
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
303
|
+
* @param newPicture - Picture to add or replace
|
|
304
|
+
* @returns Modified file buffer with picture updated
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const backCover: Picture = {
|
|
309
|
+
* mimeType: "image/png",
|
|
310
|
+
* data: pngData,
|
|
311
|
+
* type: PictureType.BackCover,
|
|
312
|
+
* description: "Back cover"
|
|
313
|
+
* };
|
|
314
|
+
* const modifiedBuffer = await replacePictureByType("song.mp3", backCover);
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
export declare function replacePictureByType(file: string | Uint8Array | ArrayBuffer | File, newPicture: Picture): Promise<Uint8Array>;
|
|
318
|
+
/**
|
|
319
|
+
* Get picture metadata without the actual image data
|
|
320
|
+
*
|
|
321
|
+
* Useful for checking what pictures are present without loading
|
|
322
|
+
* potentially large image data into memory.
|
|
323
|
+
*
|
|
324
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
325
|
+
* @returns Array of picture metadata (type, mimeType, description, size)
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const metadata = await getPictureMetadata("song.mp3");
|
|
330
|
+
* for (const info of metadata) {
|
|
331
|
+
* console.log(`${info.description}: ${info.mimeType}, ${info.size} bytes`);
|
|
332
|
+
* }
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
export declare function getPictureMetadata(file: string | Uint8Array | ArrayBuffer | File): Promise<Array<{
|
|
336
|
+
type: PictureType;
|
|
337
|
+
mimeType: string;
|
|
338
|
+
description?: string;
|
|
339
|
+
size: number;
|
|
340
|
+
}>>;
|
|
341
|
+
/**
|
|
342
|
+
* Re-export commonly used types for convenience.
|
|
343
|
+
* These types define the structure of metadata and audio properties.
|
|
344
|
+
*/
|
|
345
|
+
export type { AudioProperties, Tag, Picture } from "./types.ts";
|
|
346
|
+
export { PictureType } from "./types.ts";
|
|
347
|
+
//# sourceMappingURL=simple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../../src/simple.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4BzC;;;;;;;;;;;GAWG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,GAC7C,OAAO,CAAC,GAAG,CAAC,CAcd;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,EAC9C,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,CAAC,EAAE,MA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