Registry / serialization / unzipper

unzipper

JSON →
library1.11jsnpmunverified

unzipper is a JavaScript library providing a cross-platform, streaming API for decompressing ZIP archives. Unlike many alternatives, it emphasizes random access to files within an archive without requiring the entire file to be buffered into memory, making it efficient for large ZIP files or when only specific entries are needed. The library also supports retrieving ZIP contents from remote URLs using range headers. Currently at version 0.12.3, unzipper sees irregular but consistent releases, often to address dependency updates, performance improvements, or bug fixes. Key differentiators include its streaming capabilities, random access methods (`stream()`, `buffer()`), and direct support for CRX files and remote sources.

npm install unzipper
INSTALL
IMPORT
SIG · UNZIPPER
U
unzipper
serializationjavascriptv1.11
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.

unzipper
import * as unzipper from 'unzipper';
import unzipper from 'unzipper'; const unzipper = require('unzipper');
The library exports a default object containing the Open namespace and other utilities. For ESM, prefer `import * as unzipper` to get all exports. CommonJS `require('unzipper')` works similarly. Direct default import `import unzipper` may lead to issues.
Open.file
import * as unzipper from 'unzipper'; const directory = await unzipper.Open.file('path/to/archive.zip');
import { Open } from 'unzipper'; const directory = await Open.file('path/to/archive.zip');
Open is a static property of the main unzipper export, not a named export itself. Access it via `unzipper.Open`.
directory.files[0].stream
import * as unzipper from 'unzipper'; const directory = await unzipper.Open.file('archive.zip'); directory.files[0].stream();
directory.files[0].pipe(...);
The `stream()` method returns a readable stream; you must call it to get the stream object before piping. Similarly, `buffer()` must be called to return a Promise.

This quickstart demonstrates how to open a local ZIP file, list its contents, extract all files to a specified destination, and then read the content of a specific file into a buffer using unzipper's asynchronous API.

import * as unzipper from 'unzipper'; import fs from 'fs'; import path from 'path'; async function extractZipFile(zipFilePath, destinationPath) { try { console.log(`Opening zip file: ${zipFilePath}`); const directory = await unzipper.Open.file(zipFilePath); console.log(`Found ${directory.files.length} files in the archive.`); // Ensure destination directory exists await fs.promises.mkdir(destinationPath, { recursive: true }); console.log(`Extracting to: ${destinationPath}`); // Extract all files to the destination path await directory.extract({ path: destinationPath }); console.log('All files extracted successfully!'); // Example: Read the content of a specific file as a buffer const firstFile = directory.files.find(f => !f.dir); if (firstFile) { console.log(`Reading content of first file: ${firstFile.path}`); const contentBuffer = await firstFile.buffer(); console.log(`Content of ${firstFile.path} (first 50 bytes):\n${contentBuffer.toString('utf8', 0, Math.min(contentBuffer.length, 50))}...`); } } catch (error) { console.error('Error during zip extraction:', error); process.exit(1); } } // To make this runnable, create a dummy zip file or provide a real path. // For example, using a temporary file created by another process or a known zip. // const dummyZipPath = '/tmp/test.zip'; // const dummyDestPath = '/tmp/extracted'; // extractZipFile(dummyZipPath, dummyDestPath); // Placeholder for a real zip file if running directly. // In a real application, these paths would come from user input or configuration. const exampleZipPath = process.env.ZIP_FILE_PATH || path.join(process.cwd(), 'example.zip'); const exampleDestPath = process.env.EXTRACT_TO_PATH || path.join(process.cwd(), 'extracted_files'); if (!fs.existsSync(exampleZipPath)) { console.warn(`Warning: Example zip file not found at ${exampleZipPath}. Please create one or set ZIP_FILE_PATH.`); console.warn('To test, you can create a simple zip like: `echo "hello" > file1.txt && zip example.zip file1.txt`'); } else { extractZipFile(exampleZipPath, exampleDestPath); }
Debug
Known issues
breakingSupport for ancient Node.js versions was removed with the `v0.11.2` release, which dropped polyfills. Users on very old Node.js runtimes (e.g., prior to Node.js 8 or 10, depending on specific polyfills) may experience compatibility issues.
fix
Upgrade to a modern, actively supported Node.js LTS version (e.g., Node.js 16 or newer).
affects: >=0.11.2
gotchaThe `Open.url` method requires you to provide your own HTTP request library (e.g., `node-fetch`, `axios`, or `request`) as its first argument. `unzipper` does not bundle one. Failure to provide a compatible library will result in runtime errors.
fix
Pass a compatible request library that supports fetching URLs and optionally range headers as the first argument to `unzipper.Open.url`.
affects: >=0.10.0
breakingThe internal dependency `fstream` was replaced with `fs-extra` in `v0.12.0` / `v0.12.1`, and `big-integer` with `node-int64`. While primarily internal, this could potentially lead to subtle behavioral changes in file system operations or performance characteristics, especially with large or encrypted files.
fix
Review code that relies on implicit behaviors of the underlying file system operations or integer handling when upgrading from versions prior to `v0.12.0`.
affects: >=0.12.0
gotchaThe `v0.12.3` release included an `@ts-ignore` for TypeScript errors, suggesting there may be underlying type definition issues or complexities that require manual handling when using `unzipper` in TypeScript projects. This can lead to less robust type checking.
fix
Be aware of potential type issues when using `unzipper` with TypeScript. Consider adding custom type definitions or using type assertions if errors persist, and monitor for updates to the official type definitions.
affects: >=0.12.3
Errors
Common errors & fixes
TypeError: unzipper.Open.file is not a function
Incorrect import statement or accessing `Open` directly without the `unzipper` namespace.
fix
Use `import * as unzipper from 'unzipper';` for ESM or `const unzipper = require('unzipper');` for CommonJS, then access via `unzipper.Open.file`.
Error: Corrupted zip: CRC mismatch
The ZIP file is genuinely corrupted, incomplete, or the wrong password was provided for an encrypted entry.
fix
Verify the integrity of the ZIP file, ensure it downloaded completely, and double-check the password for any encrypted files.
Error: 'Range not satisfiable' or similar HTTP 4xx error when using Open.url
The remote server hosting the ZIP file does not support HTTP Range requests, which unzipper relies on to read specific parts of the archive efficiently.
fix
Ensure the server supports Range headers. If not, you might need to download the entire ZIP file first and process it locally using `Open.file`.
Error: Missing password for encrypted file
Attempting to `stream()` or `buffer()` an encrypted file without providing the correct password.
fix
Provide the correct password as an argument to the `stream()` or `buffer()` method for encrypted file entries (e.g., `file.stream('yourPassword')`).
Upgrade
Version history
1.11latest on npm
Audit
Dependencies
requestoptionalRequired for the Open.url method to fetch remote zip files, as unzipper does not bundle a request library.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources