es-7z
Heavily reworked fork of node-7z by Quentin Rossetti that adds support for configurable 7zip path, much thanks to Quentin for doing all the hard work!
Install
npm i -S es-7z
node-7z
Differences from- Library is all ES Module syntax, compiled with babel.
- Tests are ES module syntax, compiled on the fly and run by mocha.
- Every method export takes an optional
exePath
option which is expected to be a path to 7z.exe / 7za.exe. If omitted, the default in path will be attempted.
Usage
const exePath = path // Equivalent to `on('data', function (files) { // ... });`; // When all is done; // On error;
Installation
You must have the 7za
executable available in your PATH or in the same
directory of your package.json
file OR specify it as option exePath that is
handed into each method.
On Debian an Ubuntu install the
p7zip-full
package.
On Windows use the
7za.exe
(link here) binary.
On Mac OSX use Homebrew
brew install p7zip
API
See the 7-Zip documentation for the full list of usages and options (switches).
The type of the list of files can be either String or Array.
Zip.add
Add: Arguments
archive
Path to the archive you want to create.files
The file list to add.options
An object of options (7-Zip switches).
Progress
files
A array of all the extracted files AND directories. The/
character is used as a path separator on every platform.
Error
err
An Error object.
Zip.delete
Delete: Arguments
archive
Path to the archive you want to delete files from.files
The file list to delete.options
An object of options (7-Zip switches).
Error
err
An Error object.
Zip.extract
Extract: Arguments
archive
The path to the archive you want to extract.dest
Where to extract the archive.options
An object of options.
Progress
files
A array of all the extracted files AND directories. The/
character is used as a path separator on every platform.
Error
err
An Error object.
Zip.extractFull
Extract with full paths: Arguments
archive
The path to the archive you want to extract.dest
Where to extract the archive (creates folders for you).options
An object of options.
Progress
files
A array of all the extracted files AND directories. The/
character is used as a path separator on every platform.
Error
err
An Error object.
Zip.list
List contents of archive: Arguments
archive
The path to the archive you want to analyse.options
An object of options.
Progress
files
A array of objects of all the extracted files AND directories. The/
character is used as a path separator on every platform. Object's properties are:date
,attr
,size
andname
.
Fulfill
spec
An object of tech spec about the archive. Properties are:path
,type
,method
,physicalSize
andheadersSize
(Some of them may be missing with non-7z archives).
Error
err
An Error object.
Zip.test
Test integrity of archive: Arguments
archive
The path to the archive you want to analyse.options
An object of options.
Progress
files
A array of all the extracted files AND directories. The/
character is used as a path separator on every platform.
Error
err
An Error object.
Zip.update
Update: Arguments
archive
Path to the archive you want to update.files
The file list to update.options
An object of options (7-Zip switches).
Progress
files
A array of all the extracted files AND directories. The/
character is used as a path separator on every platform.
Error
err
An Error object.
Advanced usage
Compression method
With the 7za
binary compression is made like that:
# adds *.exe and *.dll files to solid archive archive.7z using LZMA method# with 2 MB dictionary and BCJ filter.7z a archive.7z *.exe -m0=BCJ -m1=LZMA:d=21
With es-7z you can translate it like that:
;
Add, delete and update multiple files
When adding, deleting or updating archives you can pass either a string or an
array as second parameter (the files
parameter).
;
Wildcards
You can extract with wildcards to specify one or more file extensions. To do
this add a wildcards
attribute to the options
object. The wildcard
attribute takes an Array as value. In this array each item is a wildcard.
;
Note that the r
(for recursive) attribute is passed in this example.
With ❤️ from quentinrossetti and Cole Chamberlain
TEST
Unit tests output for current release:
TOC
add
should return an error on 7z error.
0 _add2default'.tmp/test/addnot.7z' '.tmp/test/nothere' '???': true ;
should return entries on progress.
0 _add2default'.tmp/test/add.zip' '*.md';
delete
should return an error on 7z error.
0 _delete2default'.tmp/test/addnot.7z' '.tmp/test/nothere' '???': true ;
should return on fulfillment.
_fsExtra2default;0 _delete2default'.tmp/test/copy.7z' '*.txt';
should accept array as source.
_fsExtra2default;0 _delete2default'.tmp/d.7z' 'zip/file0.txt' 'zip/file1.txt';
extract
should return an error on 7z error.
0 _extract2default'test/nothere.7z' '.tmp/test';
should return an error on output duplticate.
0 _extract2default'test/zip.7z' '.tmp/test' o: '.tmp/test/duplicate' ;
should return entries on progress.
0 _extract2default'test/zip.7z' '.tmp/test';
should extract on the right path.
0 _extract2default'test/zip.7z' '.tmp/test';
extractFull
should return an error on 7z error.
0 _extractFull2default'test/nothere.7z' '.tmp/test';
should return an error on output duplicate.
0 _extractFull2default'test/zip.7z' '.tmp/test' o: '.tmp/test/duplicate' ;
should return entries on progress.
0 _extractFull2default'test/zip.7z' '.tmp/test';
should extract on the right path.
0 _extractFull2default'test/zip.7z' '.tmp/test';
should extract only given wilcards.
0 _extractFull2default'test/wildcards.zip' '.tmp/test/' wildcards: '*.txt' r: true ;
should work with spaces in archive name.
0 _extractFull2default'test/zip spaces test.7z' '.tmp/test spaces one';
should work with spaces in destination.
0 _extractFull2default'test/zip.7z' '.tmp/test spaces agai n';
should work with spaces in both source and destination.
/*jshint maxlen:false*/_fsExtra2default;0 _extractFull2default'.tmp/test/Folder From/Folder A/Folder B/Folder C/zip file.7z' '.tmp/test/Folder To/Folder D/Folder E/Folder F';
list
should return an error on 7z error.
0 _list2default'test/nothere.7z';
should return an tech spec on fulfill.
0 _list2default'test/zip.7z' r: true ;
should return valid entries on progress.
0 _list2default'test/zip.zip';
test
should return an error on 7z error.
0 _test2default'test/nothere.7z';
should return entries on progress.
0 _test2default'test/zip.7z' r: true ;
update
should return an error on 7z error.
0 _update2default'.tmp/test/addnot.7z' '.tmp/test/nothere' '???': true ;
should return entries on progress.
_fsExtra2default;0 _update2default'.tmp/test/update.7z' '*.md' w: 'test' ;
should return on fulfillment.
_fsExtra2default;0 _update2default'.tmp/test/update.7z' '*.txt';
zip
should exist.
return should;
should be an object.
return zipshouldbe;
should respond to 7-Zip commands as methods.
zipshould;zipshould;zipshould;zipshould;zipshould;zipshould;zipshould;
files
Utility: should error on invalid files.
var r = 0 _files2default;to;
should works with strings.
var r = 0 _files2default'hello test';to;
should works with arrays.
var r = 0 _files2default'hello test' 'hello world';to;
run
Utility: should return an error with invalid command type.
0 _run2default0;
should return an error on when 7z gets one.
0 _run2default'7za "???"';
should return an stdout on progress.
0 _run2default'7za' h: true ;
should correctly parse complex commands.
0 _run2default'7za a ".tmp/test/archive.7z" "*.exe" "*.dll"' m0: '=BCJ' m1: '=LZMA:d=21';
should correctly parse complex commands with spaces.
0 _run2default'7za a ".tmp/Folder A/Folder B\\archive.7z" "*.exe" "*.dll"' m0: '=BCJ' m1: '=LZMA:d=21' p: 'My mhjls/\\c $^é5°';
switches
Utility: should return deflaut flags with no args.
to;to;
should return -ssc with flag { ssc: true }.
to;to;
should return -ssc- with flag { ssc: false }.
to;
should return non default booleans when specified.
var r = 0 _switches2default so: true spl: true ssw: true y: false;to;to;to;to;notto;
should return complex values when needed.
var r = 0 _switches2default ssc: true ssw: true mx0: true;to;to;to;to;
should return complex values with spaces and quotes.
var r = 0 _switches2default ssc: true ssw: true m0: '=BCJ' m1: '=LZMA:d=21' p: 'My Super Pasw,àù£*';to;to;to;to;to;to;