What is zip-a-folder?
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.
What are zip-a-folder's main functionalities?
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');
}
});
Other packages similar to zip-a-folder
archiver
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.
adm-zip
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.
node-zip
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.
zip-a-folder
Inspired by zip-folder
to just zip a complete folder plain into a zip file I
recreated this project since zip-folder was very outdated and seemed not
to be maintained anymore. Also I added support for modern ES6 language
features like promises/async/await.
Basic Usage
Install via npm
npm install zip-a-folder
Promised Usage
const zip-a-folder = require('zip-a-folder');
class ZipAFolder {
static async main() {
await zip-a-folder.zip('/path/to/the/folder', '/path/to/archive.zip');
}
}
ZipAFolder.main();
Callback Usage
const zipFolder = require('zip-a-folder');
class ZipAFolder {
static main() {
zipFolder.zipFolder('/path/to/the/folder', '/path/to/archive.zip', function(err) {
if(err) {
console.log('Something went wrong!', err);
}
});
}
}
ZipAFolder.main();
Tests
Tests are written under test
and run by jest. To run the tests call npm test
.
Thanks
- Special thanks to @sole for her initial work.