Registry / data / unzipit

unzipit

JSON →
library2.0.1jsnpmunverified

unzipit.js is a JavaScript library providing efficient, random-access decompression of ZIP archives in both browser and Node.js environments. Currently stable at version 2.0.1, it offers significant performance advantages, claiming 6x to 25x faster extraction speeds than alternatives like JSZip, coupled with considerably lower memory consumption. A key differentiating feature is its ability to perform partial downloads of ZIP files by leveraging HTTP range requests, allowing selective extraction without fetching the entire archive. The library supports parallel processing through web workers, further enhancing speed. It accepts various input types, including URLs, Blobs, ArrayBuffers, and custom `Reader` implementations, making it versatile for diverse use cases. While designed for ESM, it also provides a CommonJS entry point for Node.js projects, with recent versions (Node >=18) primarily favoring ES Modules.

npm install unzipit
INSTALL
IMPORT
SIG · UNZIPIT
U
unzipit
datajavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unzip
import { unzip } from 'unzipit';
import unzip from 'unzipit';
`unzip` is the primary named export for initiating the ZIP extraction process. Attempting a default import will fail.
setOptions
import { setOptions } from 'unzipit';
const { setOptions } = require('unzipit');
Used to configure global options like `workerURL`. While `require` might work in some Node setups, ESM is the recommended approach for this library with Node >=18.
* as unzipit (ESM)
import * as unzipit from 'unzipit';
const unzipit = require('unzipit');
Imports all exports under a namespace. `require` is incorrect for browser environments and typically for Node >=18 when using ESM.
unzipit (CommonJS)
const unzipit = require('unzipit');
This CommonJS import pattern is supported for Node.js environments. For browser or modern Node.js ESM projects, use `import` syntax.

Demonstrates basic usage of `unzipit` to fetch a ZIP file from a URL, list its contents, and extract specific entries as text and Blob objects, handling potential errors.

import { unzip } from 'unzipit'; async function processZipFromUrl(zipUrl: string) { try { // Replace with a real URL for actual testing const dataUrl = zipUrl || 'https://greggman.github.io/unzipit/test/zips/archive-with-folder.zip'; console.log(`Attempting to unzip from: ${dataUrl}`); const { entries, zip } = await unzip(dataUrl); console.log(`Total entries found: ${Object.keys(entries).length}`); // Iterate through all entries and log their names and sizes for (const [name, entry] of Object.entries(entries)) { console.log(` Entry: ${name}, Size: ${entry.size} bytes`); } // Example: Read a specific file (e.g., 'folder/file1.txt' from the example URL) const specificEntry = entries['folder/file1.txt']; if (specificEntry) { console.log(`\nAttempting to read 'folder/file1.txt' as text...`); const textContent = await specificEntry.text(); console.log(`Content of 'folder/file1.txt':\n---\n${textContent.substring(0, 100)}...\n---`); // Log first 100 chars } else { console.log(`\nEntry 'folder/file1.txt' not found (check URL or entry name).`); } // Example: Read another entry as a Blob (e.g., if there was an image.png) const imageEntry = entries['image.png']; // Replace with an actual image entry if present if (imageEntry) { console.log(`\nAttempting to read 'image.png' as a Blob...`); const imageBlob = await imageEntry.blob('image/png'); console.log(`'image.png' read as Blob of type: ${imageBlob.type}, size: ${imageBlob.size}`); // In a browser, you could create an object URL: URL.createObjectURL(imageBlob); } else { console.log(`\nEntry 'image.png' not found.`); } } catch (error) { console.error("Error processing zip file:", error); } } // Call the function with an example URL. Pass an empty string to demonstrate 'not found' messages. processZipFromUrl('https://greggman.github.io/unzipit/test/zips/archive-with-folder.zip');
Debug
Known issues
breakingUsers migrating from CommonJS (`require`) to ES Modules (`import`) or targeting modern Node.js environments (Node 18+) will experience breaking changes in import syntax.
fix
Replace `const unzipit = require('unzipit')` with `import { unzip } from 'unzipit'` or `import * as unzipit from 'unzipit'` for ES Module compatibility. Ensure your project's `package.json` specifies `"type": "module"` or uses `.mjs` file extensions for ESM.
affects: >=2.0.0
gotchaWhen using web workers for parallel processing, the `workerURL` option *must* be correctly set to the path of `unzipit-worker.module.js`.
fix
Call `setOptions({workerURL: 'path/to/unzipit-worker.module.js'})` *before* calling `unzip`. The worker script is usually found in the `dist` folder of the `unzipit` package.
affects: >=1.0.0
gotchaIn Node.js environments, `unzipit` cannot directly fetch from URLs without a custom `Reader` or by pre-loading the ZIP content into an `ArrayBuffer`, `SharedArrayBuffer`, or `TypedArray`.
fix
For Node.js, first read the file into a buffer using `fsPromises.readFile()` or use a library like `node-fetch` to get a `Blob` or `ArrayBuffer` from a URL, then pass that data to `unzip`.
affects: >=1.0.0
gotchaThe `unzip` function returns a `Zip` object with an `entries` property, which is a plain object mapping entry names to `ZipEntry` objects. Directly iterating over `entries` as an array will fail.
fix
Use `Object.entries(entries)`, `Object.keys(entries)`, or `Object.values(entries)` to iterate over the entries, as shown in the examples.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , unzipit__WEBPACK_IMPORTED_MODULE_0__.unzip) is not a function
Incorrect import syntax for named exports, typically attempting a default import for `unzip`.
fix
Use a named import: `import { unzip } from 'unzipit';`.
ReferenceError: require is not defined
Attempting to use CommonJS `require` syntax in an ES Module environment (browser, or Node.js project configured for ESM).
fix
Use ES Module `import` statements (e.g., `import { unzip } from 'unzipit'`) or ensure your Node.js project is configured for CommonJS (`"type": "commonjs"` in `package.json`).
Failed to construct 'Worker': Script at 'path/to/unzipit-worker.module.js' cannot be accessed from origin 'null'.
The `workerURL` provided to `setOptions` points to an inaccessible or improperly served path for the web worker script.
fix
Ensure `workerURL` is a valid, publicly accessible URL relative to your web application's origin, or a data URL. Double-check the path to `unzipit-worker.module.js` in your `dist` folder.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
unzipit — npm install unzipit · libregistry