UNPKG

taglib-wasm

Version:

TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps

43 lines (42 loc) 1.52 kB
import { applyCoverArt, replacePictureByType } from "../simple/index.js"; import { readFileData } from "../utils/file.js"; import { writeFileData } from "../utils/write.js"; import { detectMimeType } from "./mime-detection.js"; import { basename } from "../utils/path.js"; async function importCoverArt(audioPath, imagePath, options = {}) { const imageData = await readFileData(imagePath); const mimeType = detectMimeType(imagePath, options.mimeType); const modifiedBuffer = await applyCoverArt(audioPath, imageData, mimeType); await writeFileData(audioPath, modifiedBuffer); } async function importPictureWithType(audioPath, imagePath, type, options = {}) { const imageData = await readFileData(imagePath); const mimeType = detectMimeType(imagePath, options.mimeType); const picture = { mimeType, data: imageData, type, description: options.description }; const modifiedBuffer = await replacePictureByType(audioPath, picture); await writeFileData(audioPath, modifiedBuffer); } async function loadPictureFromFile(imagePath, type = "FrontCover", options = {}) { const data = await readFileData(imagePath); const mimeType = detectMimeType(imagePath, options.mimeType); return { mimeType, data, type, description: options.description ?? basename(imagePath) }; } async function savePictureToFile(picture, imagePath) { await writeFileData(imagePath, picture.data); } export { importCoverArt, importPictureWithType, loadPictureFromFile, savePictureToFile };