1.0.0 • Published 2 years ago
als-zip-tools v1.0.0
als-zip-tools
A Node.js library for efficiently zipping and unzipping files. als-zip-tools provides a simple and powerful way to create zip archives and extract contents from zip files, supporting both basic and advanced use cases.
Installation
npm install als-zip-toolsUsage
Zipping Files
To create a zip file, simply use the zip function.
const { zip } = require('als-zip-tools');
const files = {
'example.txt': Buffer.from('Example content'),
'data.json': Buffer.from(JSON.stringify({ key: 'value' }))
};
zip(files).then(buffer => {
// Do something with the zip buffer
});Unzipping Files
To extract files from a zip archive, use the unzip function.
const { unzip } = require('als-zip-tools');
unzip(zipBuffer).then(files => {
// files is an object with file names as keys and Buffers as values
});Applying Filters in Unzipping
You can also apply a filter function to select specific files during unzipping.
unzip(zipBuffer, (path) => path.endsWith('.txt')).then(files => {
// Only txt files will be returned
});API
zip(files, level)
files\: Object with file paths as keys and Buffers as values.level\: (optional) Compression level, default is 9.
Returns a Promise resolved with a Buffer of the zip file.
unzip(buffer, filter)
buffer\: Buffer of the zip file.filter\: (optional) A function that takes a file path and returns true to include the file.
Returns a Promise resolved with an object containing unzipped files.
1.0.0
2 years ago