-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.mjs
35 lines (31 loc) · 1 KB
/
main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { readFile } from 'node:fs/promises';
import { Worker } from 'node:worker_threads';
import { ArchiveReader, libarchiveWasm } from 'libarchive-wasm';
import { wrap } from 'minlink/dist/node.mjs';
(async () => {
const data = await readFile('../../archives/deflate.zip');
await (async () => {
console.log('Extract (main)');
const mod = await libarchiveWasm();
const reader = new ArchiveReader(mod, new Int8Array(data));
for (const entry of reader.entries()) {
const result = {
pathname: entry.getPathname(),
size: entry.getSize(),
};
if (result.pathname.endsWith('.md')) {
result.data = new TextDecoder().decode(entry.readData());
}
console.log(result);
}
reader.free();
})();
await (async () => {
console.log('Extract (worker)');
const worker = new Worker('./worker.mjs');
const api = wrap(worker);
const results = await api.exec('extractAll', data);
console.log(results);
await api.terminate();
})();
})();