What is cross-zip?
The cross-zip npm package is a utility for zipping and unzipping files and directories in a cross-platform manner. It is designed to work seamlessly on both Windows and Unix-like systems, making it a versatile tool for handling zip files in Node.js applications.
What are cross-zip's main functionalities?
Zip a directory
This feature allows you to zip an entire directory. The code sample demonstrates how to zip a directory named 'sourceDir' into a file named 'output.zip'.
const crossZip = require('cross-zip');
crossZip.zip('sourceDir', 'output.zip', (err) => {
if (err) {
console.error('Error zipping directory:', err);
} else {
console.log('Directory zipped successfully');
}
});
Unzip a file
This feature allows you to unzip a zip file into a specified directory. The code sample demonstrates how to unzip a file named 'input.zip' into a directory named 'destinationDir'.
const crossZip = require('cross-zip');
crossZip.unzip('input.zip', 'destinationDir', (err) => {
if (err) {
console.error('Error unzipping file:', err);
} else {
console.log('File unzipped successfully');
}
});
Other packages similar to cross-zip
adm-zip
ADM-ZIP is a pure JavaScript implementation for zip data compression for NodeJS. It allows you to create, read, and extract zip files. Compared to cross-zip, ADM-ZIP offers more advanced features like adding files to an existing zip and extracting specific files from a zip.
yazl
Yazl is a zip file creation library with a focus on performance and streaming. It allows you to create zip files with a streaming API, which can be more efficient for large files. Unlike cross-zip, yazl does not provide unzipping functionality; it focuses solely on creating zip files.
archiver
Archiver is a streaming interface for archive generation, supporting zip and other formats. It provides a comprehensive API for creating archives and is highly configurable. Archiver is more feature-rich compared to cross-zip, offering support for multiple archive formats and advanced options for compression.
cross-zip

Cross-platform .zip file creation
install
npm install cross-zip
usage
var zip = require('cross-zip')
var inPath = path.join(__dirname, 'myFolder')
var outPath = path.join(__dirname, 'myFile.zip')
zip.zipSync(inPath, outPath)
api
zip.zip(inPath, outPath, [callback])
Zip the folder at inPath
and save it to a .zip file at outPath
. If a callback
is passed, then it is called with an Error
or null
.
zip.zipSync(inPath, outPath)
Sync version of zip.zip
.
zip.unzip(inPath, outPath, [callback])
Unzip the .zip file at inPath
into the folder at outPath
. If a callback
is
passed, then it is called with an Error
or null
.
zip.unzipSync(inPath, outPath)
Sync version of zip.unzip
.
Windows users
This package requires .NET Framework 4.5 or later
and Powershell 3.
These come pre-installed on Windows 8 or later.
On Windows 7 or earlier, you will need to install these manually in order for
cross-zip
to function correctly.
reference
related
license
MIT. Copyright (c) Feross Aboukhadijeh.