mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-18 00:33:59 +00:00
feat: added support to unrar files
This commit is contained in:
25
src/main/services/unrar.ts
Normal file
25
src/main/services/unrar.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Extractor, createExtractorFromFile } from 'node-unrar-js';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const wasmBinary = fs.readFileSync(require.resolve('node-unrar-js/esm/js/unrar.wasm'));
|
||||
|
||||
export class Unrar {
|
||||
private constructor(private extractor: Extractor<Uint8Array>) { }
|
||||
|
||||
static async fromFilePath(filePath: string, targetFolder: string) {
|
||||
console.log(filePath, targetFolder);
|
||||
const extractor = await createExtractorFromFile({
|
||||
filepath: filePath,
|
||||
targetPath: targetFolder,
|
||||
wasmBinary,
|
||||
});
|
||||
return new Unrar(extractor);
|
||||
}
|
||||
|
||||
extract() {
|
||||
const files = this.extractor.extract().files;
|
||||
for (const file of files) {
|
||||
console.log("File:", file.fileHeader.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user