UNPKG

igir

Version:

🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.

76 lines (75 loc) • 2.07 kB
import module from "node:module"; import os from "node:os"; import stream from "node:stream"; import Defaults from "../../src/globals/defaults.js"; const require2 = module.createRequire(import.meta.url); const ContainerFormat = { GCZ: "GCZ", WIA: "WIA", RVZ: "RVZ" }; const binding = (() => { try { return require2( `./addon-dolphin-tool/prebuilds/${os.platform()}-${os.arch()}/node.node` ); } catch { } return require2("./addon-dolphin-tool/build/Release/dolphin-tool.node"); })(); function readableFromReader(reader) { let isClosed = false; const closeOnce = () => { if (isClosed) { return; } isClosed = true; reader.close(); }; return new stream.Readable({ highWaterMark: Defaults.FILE_READING_CHUNK_SIZE, async read() { try { const chunk = await reader.read(Defaults.FILE_READING_CHUNK_SIZE); if (chunk === null || chunk.length === 0) { closeOnce(); this.push(null); } else { this.push(chunk); } } catch (error) { closeOnce(); this.destroy(error instanceof Error ? error : new Error(String(error))); } }, destroy(error, callback) { closeOnce(); callback(error); } }); } var dolphin_tool_default = { /** * Return structured header information about a Dolphin disc image without decompressing. */ async info(options) { const raw = await binding.info(options.inputFilename); const format = Object.values(ContainerFormat).find((value) => value === raw.format); if (format === void 0) { throw new Error(`unexpected Dolphin container format: ${raw.format}`); } return { ...raw, format }; }, /** * Open a {@link stream.Readable} over the full decompressed ISO byte range. */ async openReader(options) { const reader = binding.openReader(options.inputFilename); return await Promise.resolve(readableFromReader(reader)); } }; export { ContainerFormat, dolphin_tool_default as default }; //# sourceMappingURL=index.js.map