Skip to content

Commit

Permalink
Add a Zip object
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Aug 25, 2014
1 parent 5774c01 commit 04cdc0c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
61 changes: 35 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ node-7zip
Usage
-----

I chose to use both promises and callbacks in this library. In all cases the
API is consistent with standard use:
I chose to use *Promises* in this library. API is consistent with standard use:

Promise-style e.g:
```js
var Zip = require('7z');
var myTask = new Zip();
myTask.test('myArchive.7z').then(successHandler, errorHandler);
```
myTask.extractFull('myArchive.7z', 'destination', { p: 'myPassword' })

Callback-style e.g:
```js
var Zip = require('7z');
var myTask = new Zip();
myTask.test('myArchive.7z', function (err, files) {
if (err) errorHandler;
successHandler;
// Equivalent to `on('data', function (files) { // ... });`
.progress(function (files) {
console.log('Some files are extracted: %s', files);
});

// When all is done
.then(function () {
console.log('Extracting done!');
});

// On error
.catch(function (err, code) {
console.error('7-Zip exit with code %i', code);
console.error(err);
});
```

Expand All @@ -35,36 +39,41 @@ You must have the `7z` executable available in your PATH. In some GNU/Linux
distributions install the `p7zip-full`.

```
npm install -g 7z
npm install --save 7z
```

API
---

### Test integrity of archive: `test`
### Extract with full paths: `extractFull`

#### Arguments
**Arguments**
* `archive` The path to the archive you want to analyse.
* `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.

#### Return values
* `files` A array of all the files *AND* directories in the archives. The
`/` character is used as a path separator on every platform.
* `err` The error as issued by `child_process.exec`.
**Error**
* `err` An Error object. Its message is the message outputed by 7-Zip.
* `code` 7-Zip [exit code](http://sevenzip.sourceforge.jp/chm/cmdline/exit_codes.htm).

### Extract with full paths: `extract`
### Extract: `extract`

#### Arguments
**Arguments**
* `archive` The path to the archive you want to analyse.
* `dest` Where to extract the archive.
* `options` An object of options.

#### Return values
**Progress**
* `files` A array of all the extracted files *AND* directories. The `/`
character is used as a path separator on every platform.
* `err` The error as issued by `child_process.exec`.

#### Events
* `data` Emitted when files are extracted. Has one parameter `(files)`, an
array of files and directories processed.
**Error**
* `err` An Error object. Its message is the message outputed by 7-Zip.
* `code` 7-Zip [exit code](http://sevenzip.sourceforge.jp/chm/cmdline/exit_codes.htm).

***
With :heart: from [quentinrossetti](https://github.com/quentinrossetti)
Expand Down
10 changes: 6 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

module.exports = {
extract: require('./extract'),
extractFull: require('./extractFull')
};
var Zip = function () {};

Zip.prototype.extract = require('./extract');
Zip.prototype.extractFull = require('./extractFull');

module.exports = Zip;
2 changes: 1 addition & 1 deletion test/lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require('fs');
var rimraf = require('rimraf');
var extract = require('../../lib/extract');

describe('Module: `extract`', function () {
describe('Method: `Zip.extract`', function () {

afterEach(function () { rimraf.sync('.tmp/test'); });

Expand Down
2 changes: 1 addition & 1 deletion test/lib/extractFull.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require('fs');
var rimraf = require('rimraf');
var extractFull = require('../../lib/extractFull');

describe('Module: `extractFull`', function () {
describe('Method: `Zip.extractFull`', function () {

afterEach(function () { rimraf.sync('.tmp/test'); });

Expand Down
13 changes: 13 additions & 0 deletions test/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*global describe, it */
var expect = require('chai').expect;
var Zip = require('../../lib');

describe('Class: `Zip`', function () {

it('should be instanciable', function () {
var zip = new Zip();
expect(zip).to.respondTo('extract');
expect(zip).to.respondTo('extractFull');
});

});

0 comments on commit 04cdc0c

Please sign in to comment.