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.
121 lines (120 loc) • 3.42 kB
JavaScript
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 CHDType = {
CD_ROM: "CD_ROM",
DVD_ROM: "DVD_ROM",
GD_ROM: "GD_ROM",
HARD_DISK: "HARD_DISK",
RAW: "RAW"
};
const TrackReaderMode = {
CUEBIN: "cuebin",
GDI: "gdi"
};
const ChdmanMode = {
CUEBIN: 1,
GDI: 2
};
const binding = (() => {
try {
return require2(
`./addon-chdman/prebuilds/${os.platform()}-${os.arch()}/node.node`
);
} catch {
}
return require2("./addon-chdman/build/Release/chdman.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 chdman_default = {
/**
* Return structured information about a CHD file's header.
*/
async info(options) {
const raw = await binding.info(options.inputFilename);
const type = Object.values(CHDType).find((value) => value === raw.type);
if (type === void 0) {
throw new Error(`unexpected CHD type: ${raw.type}`);
}
return { ...raw, type };
},
/**
* List the tracks of a CD-ROM CHD as they would be extracted to a .cue/.bin
* pair, returning the cue TOC text and a descriptor for every track.
*/
async listCdBinCueTracks(options) {
return await binding.listTracks(
options.inputFilename,
ChdmanMode.CUEBIN,
options.binNamePattern,
options.cueName
);
},
/**
* List the tracks of a GD-ROM CHD as they would be extracted to a .gdi plus
* split track files, returning the gdi TOC text and a descriptor for every track.
*/
async listGdRomTracks(options) {
return await binding.listTracks(
options.inputFilename,
ChdmanMode.GDI,
options.trackBaseName,
options.gdiName
);
},
/**
* Open a {@link stream.Readable} over a single CD-ROM (cue/bin) or GD-ROM (gdi) track,
* yielding exactly the bytes chdman writes for that split-bin track.
*/
async openTrackReader(options) {
const mode = options.mode === TrackReaderMode.GDI ? ChdmanMode.GDI : ChdmanMode.CUEBIN;
const reader = binding.openTrackReader(options.inputFilename, mode, options.trackIndex);
return await Promise.resolve(readableFromReader(reader));
},
/**
* Open a {@link stream.Readable} over the full logical byte range of a RAW, HARD_DISK, or
* DVD CHD, yielding exactly the bytes chdman's extractRaw would write.
*/
async openRawReader(options) {
const reader = binding.openRawReader(options.inputFilename);
return await Promise.resolve(readableFromReader(reader));
}
};
export {
CHDType,
TrackReaderMode,
chdman_default as default
};
//# sourceMappingURL=index.js.map