Files
isocreator/ts/classes/iso-extractor.ts

83 lines
2.0 KiB
TypeScript

/**
* ISO Extractor
* Extracts ISO contents using xorriso
*/
import { log } from '../logging.ts';
import { getTempDir, ensureDir, cleanDir } from '../paths.ts';
import { path } from '../plugins.ts';
export class IsoExtractor {
/**
* Extract an ISO to a directory
*/
async extract(isoPath: string, extractDir?: string): Promise<string> {
// Use temp dir if not specified
const outputDir = extractDir || path.join(getTempDir(), `iso-extract-${Date.now()}`);
await cleanDir(outputDir);
await ensureDir(outputDir);
log.info(`Extracting ISO to ${outputDir}...`);
// Use xorriso to extract the ISO
const command = new Deno.Command('xorriso', {
args: [
'-osirrox',
'on',
'-indev',
isoPath,
'-extract',
'/',
outputDir,
],
stdout: 'piped',
stderr: 'piped',
});
const process = command.spawn();
const { code, stdout, stderr } = await process.output();
if (code !== 0) {
const errorText = new TextDecoder().decode(stderr);
throw new Error(`Failed to extract ISO: ${errorText}`);
}
log.success(`ISO extracted successfully to ${outputDir}`);
return outputDir;
}
/**
* Check if xorriso is installed
*/
async checkDependencies(): Promise<boolean> {
try {
const command = new Deno.Command('xorriso', {
args: ['--version'],
stdout: 'null',
stderr: 'null',
});
const { code } = await command.output();
return code === 0;
} catch {
return false;
}
}
/**
* Ensure xorriso is installed
*/
async ensureDependencies(): Promise<void> {
const hasXorriso = await this.checkDependencies();
if (!hasXorriso) {
log.error('xorriso is not installed!');
log.info('Install xorriso:');
log.info(' Ubuntu/Debian: sudo apt install xorriso');
log.info(' macOS: brew install xorriso');
throw new Error('Missing dependency: xorriso');
}
}
}