node-zip: Legacy Zip/Unzip Utility

1.1.1 · abandoned · verified Sun Apr 19

node-zip is a Node.js library for zipping and unzipping files, originally ported from an older version of JSZip. The current and only stable version is 1.1.1, which was last published over a decade ago in May 2015. This package is explicitly identified as a legacy and unmaintained project by the wider Node.js community, with strong recommendations against its use in new development due to potential security vulnerabilities, lack of modern features, and inherent performance limitations for large files. Modern alternatives like `jszip`, `adm-zip`, or `zip-stream` are recommended for active projects, offering better maintenance, asynchronous APIs, and streaming capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a ZIP archive with text and binary content, save it to disk, and then read/extract files from the created ZIP using `node-zip`.

const fs = require('fs');
const Zip = require('node-zip');

// --- Zipping a file ---
const zip = new Zip();
zip.file('my_test.txt', 'Hello, this is a test file content.');
zip.file('another_folder/image.jpg', 'fake image data here, imagine a buffer'); // Can add binary data

const zippedData = zip.generate({ base64: false, compression: 'DEFLATE' });

// IMPORTANT: When writing to a file, use 'binary' encoding.
fs.writeFileSync('output.zip', zippedData, 'binary');
console.log('Successfully created output.zip');

// --- Unzipping a file ---
// For demonstration, we'll read the file we just created
const zipBuffer = fs.readFileSync('output.zip', 'binary');

const unzip = new Zip(zipBuffer, { base64: false, checkCRC32: true });

console.log('\n--- Unzipped Content ---');
console.log('Content of my_test.txt:', unzip.files['my_test.txt'].asText());
// For binary files, you'd access .asBinary() or .asNodeBuffer()
console.log('File metadata for another_folder/image.jpg:', unzip.files['another_folder/image.jpg']);

view raw JSON →