chdman
Version:
💿 chdman binaries and wrapper for Node.js.
80 lines • 3.56 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import util from 'node:util';
import fs from 'node:fs';
import ChdmanBin from './chdmanBin.js';
import ChdmanInfo from './chdmanInfo.js';
export default {
/**
* Create a CD CHD.
*/
createCd(options) {
return __awaiter(this, void 0, void 0, function* () {
let existedBefore;
try {
yield util.promisify(fs.stat)(options.outputFilename);
existedBefore = true;
}
catch (_a) {
existedBefore = false;
}
try {
yield ChdmanBin.run([
'createcd',
'--output', options.outputFilename,
...(options.outputParentFilename ? ['--outputparent', String(options.outputParentFilename)] : []),
...(options.force === true ? ['--force'] : []),
'--input', options.inputFilename,
...(options.hunkSize === undefined ? [] : ['--hunksize', String(options.hunkSize)]),
...(options.compression === undefined
? []
: ['--compression', Array.isArray(options.compression) ? options.compression.join(',') : options.compression]),
...(options.numProcessors === undefined ? [] : ['--numprocessors', String(options.numProcessors)]),
], options);
}
catch (error) {
// chdman can leave cruft when it fails
if (!existedBefore) {
yield util.promisify(fs.rm)(options.outputFilename, { force: true });
}
throw error;
}
// Test the created file
try {
yield ChdmanInfo.info({
inputFilename: options.outputFilename,
});
}
catch (error) {
throw new Error(`created CHD is invalid: ${error}`);
}
});
},
/**
* Extract a CD CHD.
*
* For BIN/CUE discs, {@link options.outputFilename} should be the `.cue` file.
* For GDI/ISO/etc. discs, {@link options.outputFilename} should be the single file.
*/
extractCd(options) {
return __awaiter(this, void 0, void 0, function* () {
yield ChdmanBin.run([
'extractcd',
'--output', options.outputFilename,
...(options.outputBinFilename ? ['--outputbin', options.outputBinFilename] : []),
...(options.splitBin ? ['--splitbin'] : []),
...(options.force === true ? ['--force'] : []),
'--input', options.inputFilename,
...(options.inputParentFilename ? ['--inputparent', options.inputParentFilename] : []),
], options);
});
},
};
//# sourceMappingURL=chdmanCd.js.map