UNPKG

taglib-wasm

Version:

TagLib for TypeScript platforms: Deno, Node.js, Bun, Electron, browsers, and Cloudflare Workers

34 lines (33 loc) 1.02 kB
import { EnvironmentError, FileOperationError } from "../errors.js"; async function writeFileData(path, data) { try { if (typeof globalThis.Deno !== "undefined") { await globalThis.Deno.writeFile(path, data); return; } if (typeof globalThis.process !== "undefined" && globalThis.process.versions && globalThis.process.versions.node) { const { writeFile } = await import("fs/promises"); await writeFile(path, data); return; } if (typeof globalThis.Bun !== "undefined") { await globalThis.Bun.write(path, data); return; } } catch (error) { throw new FileOperationError( "write", error.message, path ); } const env = typeof globalThis.Deno !== "undefined" ? "Deno" : typeof globalThis.process !== "undefined" ? "Node.js" : typeof globalThis.Bun !== "undefined" ? "Bun" : "Browser"; throw new EnvironmentError( env, "does not support file path writing", "filesystem access" ); } export { writeFileData };