A utility for running sevenzip
npm install sevenzipA utility for running sevenzip from node.
- Node.js >= 18.0.0
- The 7z executable must be available on your system
``bash`
npm install sevenzip
This library supports both ES Modules (ESM) and CommonJS (CJS).
`javascript
import SevenZip from 'sevenzip';
const sz = new SevenZip();
const files = await sz.getFiles('/path/to/archive.zip');
console.log(files);
`
`javascript
const SevenZip = require('sevenzip');
const sz = new SevenZip();
const files = await sz.getFiles('/path/to/archive.zip');
console.log(files);
`
This library assumes that the 7z executable exists in the $PATH environment.setExecutable
In order to specify the location of 7z, use the constructor or :
`javascript`
const sz = new SevenZip('/usr/local/bin/7z');
or
`javascript`
const sz = new SevenZip();
sz.setExecutable('/usr/local/bin/7z');
Gets a list of files and their attributes from an archive file that sevenzip supports.
`javascript`
const files = await sz.getFiles('/path/to/archive.zip');
console.log(files);
Gets information about a single file within an archive.
`javascript`
const file = await sz.getSingleFile('/path/to/archive.zip', 'folder/file.txt');
console.log(file);
Extracts a file from an archive and returns a readable stream.
`javascript`
const stream = sz.extractFile('/path/to/archive.zip', 'folder/file.txt');
stream.pipe(process.stdout);
This package includes TypeScript definitions out of the box.
`typescript
import SevenZip from 'sevenzip';
const sz = new SevenZip();
const files = await sz.getFiles('/path/to/archive.zip');
``