Extracting archives made easy.
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 |
npm install --save @xingrz/decompress
import decompress from 'decompress';
const files = await decompress('unicorn.zip', 'dist');
console.log('done!');
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.
Type: string
| Buffer
Path of file or Buffer
to decompress.
Type: string
(optional)
Path to output directory.
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.
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!');
Type: DecompressPlugin[]
Array of plugins to use. See @xingrz/decompress-types for full definitions.
Type: number
(default: 0
)
Remove leading directory components from extracted files.
MIT © Kevin Mårtensson, XiNGRZ