Skip to content

Commit

Permalink
version 0.3.0. wildcards #3
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Feb 6, 2015
1 parent 197cf59 commit 533fa4a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

### `v0.3.0` 2015-02-06

* Feature: Add a `wildcards` parameter to the `options` object. Given
wildcards are *Array* (e.g. `[ '*.txt', '*.md' ]`).

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

* Feature: Methods `Zip.add`, `Zip.delete` and `Zip.update` can get either a
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@ archive.delete('bigArchive.7z', [ 'file1', 'file2' ])
});
```

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

```js
var archive = new Zip();
archive.extractFull('archive.zip', 'destination/', {
wildcards: [ '*.txt', '*.md' ], // extract all text and Markdown files
r: true // in each subfolder too
})
.progress(function (files) {
// Do stuff with files...
})
.then(function () {
// Do stuff...
});
```

Note that the `r` (for recursive) attribute is passed in this example.


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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-7z",
"version": "0.2.0",
"version": "0.3.0",
"description": "A Node.js wrapper for 7-Zip",
"main": "lib/index.js",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions test/lib/extractFull.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ describe('Method: `Zip.extractFull`', function () {
});
});

it('should extract only given wilcards', function (done) {
extractFull('test/wildcards.zip', '.tmp/test/', { wildcards: ['*.txt'], r: true })
.progress(function (files) {
files.forEach(function (f) {
expect(f).to.include('.txt');
});
})
.then(function () {
done();
})
.catch(function (err) {
done(err);
});
});

it('should work with spaces in archive name', function (done) {
extractFull('test/zip spaces test.7z', '.tmp/test spaces one')
.then(function () {
Expand Down
Binary file added test/wildcards.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion util/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (command, switches) {
}

// Special treatment for the output switch because it is exposed as a
// parameter in the API and not as a option.
// parameter in the API and not as a option. Plus wilcards can be passed.
var regexpOutput = /-o"((?:\\.|[^"\\])*)"/g;
var output = command.match(regexpOutput);
if (output) {
Expand Down Expand Up @@ -78,6 +78,7 @@ module.exports = function (command, switches) {
cmd: cmd,
args: args,
options: { stdio: 'pipe' } };
// console.log('>>', res.cmd, res.args.join(' '));
var run = spawn(res.cmd, res.args, res.options);
run.stdout.on('data', function (data) {
var res = reg.exec(data.toString());
Expand Down
7 changes: 6 additions & 1 deletion util/switches.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ module.exports = function (switches) {
// wrap the value with double quotes. Else just add the switch and its value
// to the string. Doubles quotes are used for parsing with a RegExp later.
if (typeof switches[s] !== 'boolean') {
if (switches[s].indexOf(' ') === -1) {

// Special treatment for wilcards
if (s === 'wildcards') {
a.unshift(switches.wildcards);
}
else if (switches[s].indexOf(' ') === -1) {
a.push('-' + s + switches[s]);
} else {
a.push('-' + s + '"' + switches[s] + '"');
Expand Down

0 comments on commit 533fa4a

Please sign in to comment.