@xingrz/decompress
v5.2.0-alpha.1
Published
Extracting archives made easy
Downloads
38
Maintainers
Readme
@xingrz/decompress
Extracting archives made easy.
Plugins
| package | version | format |
| --------------------------------------- | --------------- | ----------- |
| @xingrz/decompress-tar | | *.tar
|
| @xingrz/decompress-tarbz2 | | *.tar.bz2
|
| @xingrz/decompress-targz | | *.tar.gz
|
| @xingrz/decompress-tarzst | | *.tar.zst
|
| @xingrz/decompress-unzip | | *.zip
|
Plugin API
Install
npm install --save @xingrz/decompress
Usage
import decompress from 'decompress';
const files = await decompress('unicorn.zip', 'dist');
console.log('done!');
API
decompress(input[, output][, options])
Returns a Promise for an array of File
s in the following format:
interface File {
path: string;
type: 'file' | 'link' | 'symlink' | 'directory';
mode: number;
mtime: Date | string;
data?: Buffer;
}
If output
is not presented, data
will be populated with the content of the file. Otherwise the file will be written to disk and the data
will be undefined.
input
Type: string
| Buffer
Path of file or Buffer
to decompress.
output
Type: string
(optional)
Path to output directory.
options
filter
Type: (file: File) => boolean
Filter out files before extracting. E.g:
const files = await decompress('unicorn.zip', 'dist', {
filter: file => path.extname(file.path) !== '.exe'
});
console.log('done!');
Note that in the current implementation, filter
is only applied after fully reading all files from the archive in memory. Do not rely on this option to limit the amount of memory used by decompress
to the size of the files included by filter
. decompress
will read the entire compressed file into memory regardless.
map
Type: (file: File) => File
Map files before extracting: E.g:
const files = await decompress('unicorn.zip', 'dist', {
map: file => {
file.path = `unicorn-${file.path}`;
return file;
}
});
console.log('done!');
plugins
Type: DecompressPlugin[]
Array of plugins to use. See @xingrz/decompress-types for full definitions.
strip
Type: number
(default: 0
)
Remove leading directory components from extracted files.
License
MIT © Kevin Mårtensson, XiNGRZ