7z-extract 中文文档教程
7z-extract
7zip 的包装器,它试图提供提取状态(7z 命令实际上并没有这样做)。
Prerequisites
7z 命令是必需的,需要位于 PATH 或应用程序的根目录中,即 package.json 所在的位置。
# OSX
$ brew update && brew doctor && brew install p7zip
# Ubuntu
$ sudo apt-get install p7zip-full
Install
npm install 7z-extract --save
API
const archive = new Zip(options);
- input String - The input file path
- output String - The output path (optional, if not supplied uses /tmp)
- createFolder Boolean - Creates a random folder name to extract to the files to. (default
false
)
archive.list(); //- returns a promise, the result of which is an object including array of files in the archive
archive.extract(progress); //- extracts the archive and returns a promise, progress function optionally returns current status as object (index, totalNumberOfFiles, percentage)
Usage
查看 CBZ 文件的信息。
'use strict';
const path = require('path'),
Zip = require('../index'),
inputFile = path.join(__dirname, 'archive.zip'),
outputPath = path.join(__dirname), // optional, if not supplied uses /tmp
progress = info => {
console.log(info);
};
const archive = new Zip({ input: inputFile, output: outputPath, createFolder: true });
// archive.list()
// .then(res => { if (res){ console.log('Success!', res); } })
// .catch(err => { console.error(err); });
archive.extract(progress)
.then(res => { console.log('Success!', res); })
.catch(err => { console.error(err); });
7z-extract
Wrapper for 7zip which attempts to provide an extraction status (something the 7z command doesn't really do).
Prerequisites
The 7z command is required and needs to be in PATH or the root of your application i.e. where package.json is sitting.
# OSX
$ brew update && brew doctor && brew install p7zip
# Ubuntu
$ sudo apt-get install p7zip-full
Install
npm install 7z-extract --save
API
const archive = new Zip(options);
- input String - The input file path
- output String - The output path (optional, if not supplied uses /tmp)
- createFolder Boolean - Creates a random folder name to extract to the files to. (default
false
)
archive.list(); //- returns a promise, the result of which is an object including array of files in the archive
archive.extract(progress); //- extracts the archive and returns a promise, progress function optionally returns current status as object (index, totalNumberOfFiles, percentage)
Usage
To see info on a CBZ file.
'use strict';
const path = require('path'),
Zip = require('../index'),
inputFile = path.join(__dirname, 'archive.zip'),
outputPath = path.join(__dirname), // optional, if not supplied uses /tmp
progress = info => {
console.log(info);
};
const archive = new Zip({ input: inputFile, output: outputPath, createFolder: true });
// archive.list()
// .then(res => { if (res){ console.log('Success!', res); } })
// .catch(err => { console.error(err); });
archive.extract(progress)
.then(res => { console.log('Success!', res); })
.catch(err => { console.error(err); });