libarchive-wasm is a JavaScript library for reading various archive and compression formats. It's port of libarchive to WebAssembly and JavaScript wrapper to make it easier to use, since it runs performance should be near native.
This project was inspired by libarchive.js. libarchive-wasm only has a low level API for simpler Int8Array input and output. You can implement for different file objects and WebWorkers etc. in the browser and NodeJS as needed.
- Supported formats: ZIP, 7-Zip, RAR v4, RAR v5, TAR
- Supported compression: GZIP, DEFLATE, BZIP2, LZMA
- Built with emscripten with support for
WebAssembly.instantiateStreaming
(Support NodeJS v18+)
npm i libarchive-wasm
import { readFile } from 'node:fs/promises';
import { ArchiveReader, libarchiveWasm } from 'libarchive-wasm';
(async () => {
const data = await readFile('example.zip');
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();
})();
import { ArchiveReader, libarchiveWasm } from 'libarchive-wasm';
document.getElementById('upload').addEventListener('change', async (e) => {
const file = e.currentTarget.files[0];
const data = await file.arrayBuffer();
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();
});