mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 11:42:10 +00:00
feat: added support to unrar files
This commit is contained in:
parent
3ef2f87412
commit
76a64fca4a
1 changed files with 25 additions and 0 deletions
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue