Skip to content

Commit

Permalink
version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Oct 24, 2014
1 parent a87f174 commit 0f591d7
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 173 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Changelog
=========

### `v0.2.0` 2014-10-24

* Feature: Methods `Zip.add`, `Zip.delete` and `Zip.update` can get either a
*String* or an *Array* as `files` parameter.

### `v0.1.3` 2014-10-23

* Support for Windows platform.
* Fix: Support for Windows platform.

### `v0.1.2` 2014-10-20

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014, Quentin Rossetti <>
Copyright (c) 2014, Quentin Rossetti <quentin.rossetti@gmail.com>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ With the `7za` binary compression is made like that:
```bat
# 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 *.dll -m0=BCJ -m1=LZMA:d=21
7z a archive.7z *.exe -m0=BCJ -m1=LZMA:d=21
```

With **node-7z** you can translate it like that:

```js
var archive = new Zip();
archive.add('archive.7z', [ '*.exe' '*.dll' ], {
archive.add('archive.7z', '*.exe', {
m0: '=BCJ',
m1: '=LZMA:d=21'
})
Expand All @@ -185,8 +185,21 @@ archive.add('archive.7z', [ '*.exe' '*.dll' ], {
});
```

### 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).

```js
var archive = new Zip();
archive.delete('bigArchive.7z', [ 'file1', 'file2' ])
.then(function () {
// Do stuff...
});
```

***
With :heart: from [quentinrossetti](https://github.com/quentinrossetti)
With :heart: from [quentinrossetti](http://quentinrossetti.me/)

[david-url]: https://david-dm.org/quentinrossetti/node-7z
[david-image]: http://img.shields.io/david/quentinrossetti/node-7z.svg
Expand Down
4 changes: 2 additions & 2 deletions TOTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ TODO

- [x] Pass switches from each command to the `run` function.
- [x] Normalize path in `run`?
- [x] Multiple files in add, delete, etc.
- [x] Verify all doc
- [ ] Streaming abilities
- [ ] Multiple files in add, delete, etc.
- [ ] Verify all doc
39 changes: 19 additions & 20 deletions lib/add.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
switches : require('../util/switches')
var u = {
files : require('../util/files'),
run : require('../util/run'),
switches: require('../util/switches'),
};

/**
* Add content to an archive.
* @promise Add
* @param archive {string} Path to the archive.
* @param files {string|Array} Files to add.
* @param files {string|array} Files to add.
* @param options {Object} An object of acceptable options to 7za bin.
* @resolve {array} Arguments passed to the child-process.
* @progress {array} Listed files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, files, options) {
return when.promise(function (fulfill, reject, progress) {
return when.promise(function (resolve, reject, progress) {

var toAdd = '';
if (files instanceof Array) {
files.forEach(function (f) {
toAdd += '"' + f + '" ';
});
toAdd = toAdd.trim();
} else {
toAdd = '"' + files + '"';
}
// Convert array of files into a string if needed.
files = u.files(files);

var command = '7za a "' + archive + '" ' + toAdd;
// Create a string that can be parsed by `run`.
var command = '7za a "' + archive + '" ' + files;

// Start the command
u.run(command, options)

// When a stdout is emitted, parse each line and search for a pattern. When
// the pattern is found, extract the file (or directory) name from it and
// pass it to an array. Finally returns this array.
// pass it to an array. Finally returns this array in the progress function.
.progress(function (data) {
var entries = [];
data.split('\n').forEach(function (line) {
if (line.substr(0, 13) === 'Compressing ') {
entries.push(line.substr(13, line.length).replace(path.sep, '/'));
}
});
progress(entries);
return progress(entries);
})

.then(function () {
fulfill();
// When all is done resolve the Promise.
.then(function (args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
reject(err);
return reject(err);
});

});
Expand Down
32 changes: 20 additions & 12 deletions lib/delete.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
switches : require('../util/switches')
var u = {
files : require('../util/files'),
run : require('../util/run'),
switches: require('../util/switches'),
};

/**
* Delete content to an archive.
* @promise Delete
* @param archive {string} Path to the archive.
* @param files {string} Files to delete.
* @param options {Object} An object of acceptables options to 7z bin.
* @progress {array} Listed files and directories.
* @param files {string|array} Files to add.
* @param options {Object} An object of acceptable options to 7za bin.
* @resolve {array} Arguments passed to the child-process.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, files, options) {
return when.promise(function (fulfill, reject, progress) {
return when.promise(function (resolve, reject) {

var command = '7za d "' + archive + '" "' + files + '"';
// Convert array of files into a string if needed.
files = u.files(files);

// Create a string that can be parsed by `run`.
var command = '7za d "' + archive + '" ' + files;

// Start the command
u.run(command, options)

.then(function () {
fulfill();
// When all is done resolve the Promise.
.then(function (args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
reject(err);
return reject(err);
});

});
Expand Down
28 changes: 15 additions & 13 deletions lib/extract.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
switches : require('../util/switches')
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

/**
* Extract an archive.
* @promise Extract
* @param {string} archive Path to the archive.
* @param {string} dest Destination.
* @param options {Object} An object of acceptables options to 7z bin.
* @param options {Object} An object of acceptable options to 7za bin.
* @resolve {array} Arguments passed to the child-process.
* @progress {array} Extracted files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, dest, options) {
return when.promise(function (fulfill, reject, progress) {

if (options === undefined) {
options = {};
}
return when.promise(function (resolve, reject, progress) {

// Create a string that can be parsed by `run`.
var command = '7za e "' + archive + '" -o"' + dest + '" ';

// Start the command
u.run(command, options)

// When a stdout is emitted, parse each line and search for a pattern. When
Expand All @@ -35,15 +35,17 @@ module.exports = function (archive, dest, options) {
entries.push(line.substr(12, line.length).replace(path.sep, '/'));
}
});
progress(entries);
return progress(entries);
})

.then(function () {
fulfill();
// When all is done resolve the Promise.
.then(function (args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
reject(err);
return reject(err);
});

});
Expand Down
27 changes: 14 additions & 13 deletions lib/extractFull.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
switches : require('../util/switches')
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

/**
* Extract an archive with full paths.
* @promise ExtractFull
* @param {string} archive Path to the archive.
* @param {string} dest Destination.
* @param options {Object} An object of acceptables options to 7z bin.
* @param options {Object} An object of acceptable options to 7za bin.
* @resolve {array} Arguments passed to the child-process.
* @progress {array} Extracted files and directories.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, dest, options) {
return when.promise(function (fulfill, reject, progress) {

if (options === undefined) {
options = {};
}
return when.promise(function (resolve, reject, progress) {

// Create a string that can be parsed by `run`.
var command = '7za x "' + archive + '" -o"' + dest + '" ';

// Start the command
u.run(command, options)

// When a stdout is emitted, parse each line and search for a pattern. When
Expand All @@ -36,15 +35,17 @@ module.exports = function (archive, dest, options) {
entries.push(line.substr(12, line.length).replace(path.sep, '/'));
}
});
progress(entries);
return progress(entries);
})

.then(function () {
fulfill();
// When all is done resolve the Promise.
.then(function (args) {
return resolve(args);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
reject(err);
return reject(err);
});

});
Expand Down
34 changes: 18 additions & 16 deletions lib/list.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
'use strict';
var path = require('path');
var when = require('when');
var u = {
run: require('../util/run'),
switches : require('../util/switches')
var u = {
run : require('../util/run'),
switches: require('../util/switches')
};

/**
* List contents of archive.
* @promise List
* @param archive {string} Path to the archive.
* @param options {Object} An object of acceptables options to 7z bin.
* @param options {Object} An object of acceptable options to 7za bin.
* @progress {array} Listed files and directories.
* @filfull {Object} Tech spec about the archive.
* @resolve {Object} Tech spec about the archive.
* @reject {Error} The error as issued by 7-Zip.
*/
module.exports = function (archive, options) {
return when.promise(function (fulfill, reject, progress) {

if (options === undefined) {
options = {};
}

archive = archive.replace(/\ /g, '\\ ');
return when.promise(function (resolve, reject, progress) {

var spec = {};
/* jshint maxlen: 130 */
var regex = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([\.DA]+) +(\d+)[ \d]+ (.+)/;
/* jshint maxlen: 80 */

// Create a string that can be parsed by `run`.
var command = '7za l "' + archive + '" ';

// Start the command
u.run(command, options)

// When a stdout is emitted, parse each line and search for a pattern. When
Expand All @@ -37,7 +37,7 @@ module.exports = function (archive, options) {
data.split('\n').forEach(function (line) {

// Populate the tech specs of the archive that are passed to the
// fulfill handler.
// resolve handler.
if (line.substr(0, 7) === 'Path = ') {
spec.path = line.substr(7, line.length);
} else if (line.substr(0, 7) === 'Type = ') {
Expand All @@ -64,15 +64,17 @@ module.exports = function (archive, options) {

}
});
progress(entries);
return progress(entries);
})

// When all is done resolve the Promise.
.then(function () {
fulfill(spec);
return resolve(spec);
})

// Catch the error and pass it to the reject function of the Promise.
.catch(function (err) {
reject(err);
return reject(err);
});

});
Expand Down
Loading

0 comments on commit 0f591d7

Please sign in to comment.