wasm-zip-stream
v0.1.0
Published
streamed zip file contents for the browser
Readme
wasm-zip-stream
A WebAssembly package for reading and streaming zip archives in the browser.
Installation
Install via npm:
npm install wasm-zip-streamUsage
Initialize the WASM module before using the API:
import init, { Zip } from 'wasm-zip-stream';
await init();
const fileInput = document.getElementById('zip-input') as HTMLInputElement;
fileInput.addEventListener('change', async () => {
const file = fileInput.files?.[0];
if (!file) return;
// depending on the size of the zip file, this may take a bit.
const zip = await Zip.fromFile(file);
// Use the zip API:
const contents = zip.contents();
console.log(contents);
});API
| Method | Parameters | Return Type | Description |
| ---------------------------------------- | ------------------ | ---------------- | ------------------------------------------------------ |
| Zip.fromFile(file: File) | file: File | Promise<Zip> | Instantiate a Zip object from a File. |
| Zip.contents() | – | ZipContents | Returns metadata for each file in the archive. |
| Zip.fileNames() | – | string[] | Lists all file names in the archive. |
| Zip.comment() | – | string | Retrieves the archive comment. |
| Zip.decompressedSize() | – | bigint | Gets the total decompressed size. |
| Zip.readFile(fileName: string) | fileName: string | Uint8Array | Reads an entire file as bytes (fails for files >2GiB). |
| Zip.readFileToString(fileName: string) | fileName: string | string | Reads an entire file as a UTF-8 string. |
| Zip.stream(fileName: string) | fileName: string | ReadableStream | Streams the contents of a file. |
Developing
cargo install wasm-pack
git clone https://github.com/JoeyEamigh/wasm-zip-stream.git
cd wasm-zip-stream
wasm-pack build --target web
bun i
cd example
bun dev