als-zip-tools
v1.0.0
Published
Simple and efficient zip file manipulation for Node.js, providing utilities for zipping and unzipping files.
Downloads
4
Maintainers
Readme
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-tools
Usage
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>: Object with file paths as keys and Buffers as values.level
<Number>: (optional) Compression level, default is 9.
Returns a Promise resolved with a Buffer of the zip file.
unzip(buffer, [filter])
buffer
<Buffer>: Buffer of the zip file.filter
<Function>: (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.