Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
zip-a-folder
Advanced tools
The zip-a-folder npm package allows you to easily zip folders in Node.js applications. It provides a simple API to compress directories into zip files, making it useful for tasks such as creating backups, packaging files for distribution, or preparing files for upload.
Zip a folder
This feature allows you to zip a folder by specifying the source directory and the destination zip file path. The code sample demonstrates how to use the `zip` function to compress a folder.
const { zip } = require('zip-a-folder');
async function zipFolder() {
await zip('/path/to/source/folder', '/path/to/destination/archive.zip');
}
zipFolder();
Zip a folder with a callback
This feature allows you to zip a folder and handle the completion with a callback function. The code sample demonstrates how to use the `zip` function with a callback to handle errors and success messages.
const { zip } = require('zip-a-folder');
zip('/path/to/source/folder', '/path/to/destination/archive.zip', (err) => {
if (err) {
console.error('Error zipping folder:', err);
} else {
console.log('Folder successfully zipped');
}
});
The archiver package is a versatile library for creating zip and tar archives. It provides more advanced features compared to zip-a-folder, such as support for multiple archive formats, streaming, and more fine-grained control over the compression process.
The adm-zip package is another popular library for handling zip files in Node.js. It offers a wide range of functionalities, including creating, reading, and extracting zip files. It also provides more control over the zip file structure and supports various compression levels.
The node-zip package is a simple library for creating and manipulating zip files in Node.js. It is similar to zip-a-folder in terms of simplicity and ease of use, but it also allows for more detailed manipulation of zip file contents, such as adding individual files or directories.
Easy to use zip (or tar) a complete folder or a list of globs plain into a zip/tar/tgz file including compression ratio handling and custom write streams.
Install via npm
npm install zip-a-folder
import { zip } from 'zip-a-folder';
class TestMe {
static async main() {
await zip('/path/to/the/folder', '/path/to/archive.zip');
}
}
TestMe.main();
import { tar } from 'zip-a-folder';
class TestMe {
static async main() {
await tar('/path/to/the/folder', '/path/to/archive.tgz');
}
}
TestMe.main();
For the sake of easy use, supported compression levels are (by now):
COMPRESSION_LEVEL.high
, COMPRESSION_LEVEL.medium
or COMPRESSION_LEVEL.uncompressed
.
The default compression - level is high
.
import { zip, COMPRESSION_LEVEL } from 'zip-a-folder';
class TestMe {
static async main() {
await zip('/path/to/the/folder', '/path/to/archive.zip', {compression: COMPRESSION_LEVEL.high});
}
}
TestMe.main();
You can now pipe output to any WriteStream (just pass WriteStream as a parameter).
To keep the existing api stable the 2nd parameter (targetFilePath) can now be either undefined or an empty string.
ATTENTION: customWriteStream
is not checked. So it is up to the user to check
on non-existing target folders or if the targetfolder equals to the sourcefolder
(ending up in circularity).
import { zip, COMPRESSION_LEVEL } from 'zip-a-folder';
import { fs } from 'fs';
class TestMe {
static async main() {
const customWS = fs.createWriteStream('test/1234.zip');
await zipafolder.zip(path.resolve(__dirname, 'data/'), undefined, {customWriteStream: customWS});
}
}
TestMe.main();
The first parameter can be either a path or a glob. Globs are separated by comma.
import {zip} from 'zip-a-folder';
class TestMe {
static async main() {
// zip all json into an archive
await zip('**/*.json', '/path/to/archive.zip');
// zip all json AND txt files into a second archive
await zip('**/*.json, **/*.txt', '/path/to/archive2.zip');
}
}
TestMe.main();
With passing a destination path to zip-a-folder options object you can define the target folder structure within the generated zip.
import {zip} from 'zip-a-folder';
class TestMe {
static async main() {
// zip all json into an archive
await zip('data/', '/path/to/archive.zip', {destPath: 'data/'});
}
}
TestMe.main();
Tests can be found in /test
and run by jest. To run the tests call npm test
.
FAQs
Zip/Tar a complete folder or a glob list into a zip/tgz file
The npm package zip-a-folder receives a total of 150,868 weekly downloads. As such, zip-a-folder popularity was classified as popular.
We found that zip-a-folder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.