Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: archiverjs/node-archiver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1e55f081f0ad96622990da016e7f1ea091143c16
Choose a base ref
...
head repository: archiverjs/node-archiver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 13baccba8d3d1742495610bacca39be9842dd46e
Choose a head ref
  • 17 commits
  • 8 files changed
  • 1 contributor

Commits on May 23, 2015

  1. Copy the full SHA
    70549f2 View commit details

Commits on May 30, 2015

  1. Copy the full SHA
    b48f4b4 View commit details
  2. Copy the full SHA
    fbb9676 View commit details
  3. few more vending fixes.

    ctalkington committed May 30, 2015
    Copy the full SHA
    75568f8 View commit details
  4. Copy the full SHA
    2aae944 View commit details

Commits on Jun 5, 2015

  1. update README [ci skip]

    ctalkington committed Jun 5, 2015
    Copy the full SHA
    4d25ea6 View commit details
  2. support using a function to adjust data properties for methods that d…

    …eal with multiple entries such as bulk and directory.
    ctalkington committed Jun 5, 2015
    2
    Copy the full SHA
    6688585 View commit details
  3. Copy the full SHA
    32bdebd View commit details
  4. Copy the full SHA
    1138d5f View commit details
  5. Copy the full SHA
    c0f3b86 View commit details
  6. Copy the full SHA
    150bb3e View commit details
  7. Copy the full SHA
    3c08a69 View commit details

Commits on Jun 6, 2015

  1. appveyor

    ctalkington committed Jun 6, 2015
    Copy the full SHA
    e8c09ab View commit details

Commits on Aug 22, 2015

  1. update deps.

    ctalkington committed Aug 22, 2015
    Copy the full SHA
    3551c02 View commit details
  2. Copy the full SHA
    99ebec9 View commit details
  3. update travis

    ctalkington committed Aug 22, 2015
    Copy the full SHA
    ea84cbd View commit details
  4. Copy the full SHA
    13baccb View commit details
Showing with 176 additions and 61 deletions.
  1. +3 −1 .travis.yml
  2. +32 −11 README.md
  3. +23 −0 appveyor.yml
  4. +13 −17 lib/archiver.js → index.js
  5. +66 −15 lib/core.js
  6. +12 −11 package.json
  7. +26 −5 test/archiver.js
  8. +1 −1 test/plugins.js
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -3,4 +3,6 @@ language: node_js
node_js:
- "iojs"
- "0.12"
- "0.10"
- "0.10"
matrix:
fast_finish: true
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Archiver v0.14.4 [![Build Status](https://travis-ci.org/archiverjs/node-archiver.svg?branch=master)](https://travis-ci.org/archiverjs/node-archiver)
# Archiver v0.15.0 [![Build Status](https://travis-ci.org/archiverjs/node-archiver.svg?branch=master)](https://travis-ci.org/archiverjs/node-archiver) [![Build status](https://ci.appveyor.com/api/projects/status/38kqu3yp159nodxe/branch/master?svg=true)](https://ci.appveyor.com/project/ctalkington/node-archiver/branch/master)

a streaming interface for archive generation

@@ -10,21 +10,22 @@ a streaming interface for archive generation
npm install archiver --save
```

You can also use `npm install https://github.com/archiverjs/node-archiver/archive/master.tar.gz` to test upcoming versions.
## Usage

## Archiver

#### create(format, options)
```js
var archiver = require('archiver');
var archive = archiver.create('zip', {}); // or archiver('zip', {});
```

Creates an Archiver instance based on the format (zip, tar, etc) passed. Parameters can be passed directly to `Archiver` constructor for convenience.
## API

#### registerFormat(format, module)
#### Transform

Registers an archive format. Format modules are essentially transform streams with a few required methods. They will be further documented once a formal spec is in place.
Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) methods.

### Instance Methods
#### create(format, options)

Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) methods.
Creates an Archiver instance based on the format (zip, tar, etc) passed. Parameters can be passed directly to `Archiver` constructor for convenience.

#### abort()

@@ -61,10 +62,16 @@ The `data` property can be set (per src-dest mapping) to define data for matched
```js
archive.bulk([
{ src: ['mydir/**'], data: { date: new Date() } },
{ src: ['mydir/**'], data: function(data) {
data.date = new Date();
return data;
}},
{ expand: true, cwd: 'mydir', src: ['**'], dest: 'newdir' }
]);
```

As of v0.15, the `data` property can also be a function that receives data for each matched entry and is expected to return it after making any desired adjustments.

For more detail on this feature, please see [BULK.md](https://github.com/archiverjs/node-archiver/blob/master/BULK.md).

#### directory(dirpath[, destpath, data])
@@ -80,8 +87,14 @@ archive.directory('mydir', 'abc');

// mydir/ -> archive.ext/
archive.directory('mydir', false, { date: new Date() });
archive.directory('mydir', false, function(data) {
data.date = new Date();
return data;
});
```

As of v0.15, the `data` property can also be a function that receives data for each entry and is expected to return it after making any desired adjustments.

#### file(filepath, data)

Appends a file given its filepath using a [lazystream](https://github.com/jpommerening/node-lazystream) wrapper to prevent issues with open file limits. When the instance has received, processed, and emitted the file, the `entry` event is fired.
@@ -100,6 +113,10 @@ Finalizes the instance and prevents further appending to the archive structure (

Returns the current byte length emitted by archiver. Use this in your end callback to log generated size.

#### use(plugin)

Add a plugin to the middleware stack. Currently this is designed for passing the module to use (replaces registerFormat/setFormat/setModule)

## Events

Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) events.
@@ -198,7 +215,11 @@ Sets the fs stat data for this entry. This allows for reduction of fs stat calls

## Custom Formats

Archiver ships with out of the box support for TAR and ZIP archives. You can register additional formats with `registerFormat`.
Archiver ships with out of the box support for TAR and ZIP archives.

You can register additional formats with `registerFormat`.

_Formats will be changing in the next few releases to implement a middleware approach._

## Libraries

23 changes: 23 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
init:
- git config --global core.autocrlf input
environment:
matrix:
- nodejs_version: '1' # iojs
- nodejs_version: '0.12'
- nodejs_version: '0.10'
install:
- ps: Install-Product node $env:nodejs_version
- set CI=true
- npm -g install npm@latest
- set PATH=%APPDATA%\npm;%PATH%
- npm install
matrix:
fast_finish: true
build: off
version: '{build}'
shallow_clone: true
clone_depth: 1
test_script:
- node --version
- npm --version
- npm test
30 changes: 13 additions & 17 deletions lib/archiver.js → index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/**
* node-archiver
*
* Copyright (c) 2012-2014 Chris Talkington, contributors.
* Copyright (c) 2015 Chris Talkington.
* Licensed under the MIT license.
* https://github.com/archiverjs/node-archiver/blob/master/LICENSE-MIT
* https://github.com/archiverjs/node-archiver/blob/master/LICENSE
*/
var ArchiverCore = require('./core');

var Archiver = require('./lib/core');

var formats = {};

var archiver = module.exports = function(format, options) {
return archiver.create(format, options);
var vending = module.exports = function(format, options) {
return vending.create(format, options);
};

archiver.create = function(format, options) {
vending.create = function(format, options) {
if (formats[format]) {
var instance = new ArchiverCore(options);
var instance = new Archiver(format, options);
instance.setFormat(format);
instance.setModule(new formats[format](options));

@@ -24,7 +26,7 @@ archiver.create = function(format, options) {
}
};

archiver.registerFormat = function(format, module) {
vending.registerFormat = function(format, module) {
if (formats[format]) {
throw new Error('register(' + format + '): format already registered');
}
@@ -38,14 +40,8 @@ archiver.registerFormat = function(format, module) {
}

formats[format] = module;

// backwards compat - to be removed in 0.14
var compatName = 'create' + format.charAt(0).toUpperCase() + format.slice(1);
archiver[compatName] = function(options) {
return archiver.create(format, options);
};
};

archiver.registerFormat('zip', require('./plugins/zip'));
archiver.registerFormat('tar', require('./plugins/tar'));
archiver.registerFormat('json', require('./plugins/json'));
vending.registerFormat('zip', require('./lib/plugins/zip'));
vending.registerFormat('tar', require('./lib/plugins/tar'));
vending.registerFormat('json', require('./lib/plugins/json'));
81 changes: 66 additions & 15 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -5,17 +5,21 @@
* Licensed under the MIT license.
* https://github.com/archiverjs/node-archiver/blob/master/LICENSE-MIT
*/
var async = require('async');
var fs = require('fs');
var util = require('./util');

var inherits = require('util').inherits;
var Transform = require('readable-stream').Transform;

var async = require('async');

var util = require('./util');

var Archiver = module.exports = function(options) {
var Archiver = module.exports = function(format, options) {
if (!(this instanceof Archiver)) {
return new Archiver(options);
return new Archiver(format, options);
}

if (typeof format !== 'string') {
options = format;
format = 'zip';
}

options = this.options = util.defaults(options, {
@@ -43,6 +47,8 @@ var Archiver = module.exports = function(options) {
finalized: false,
modulePiped: false
};

this._streams = [];
};

inherits(Archiver, Transform);
@@ -190,12 +196,13 @@ Archiver.prototype._normalizeEntryData = function(data, stats) {
}
}

// 511 === 0777; 493 === 0755; 420 === 0644
if (typeof data.mode === 'number') {
data.mode &= 0777;
data.mode &= 511;
} else if (data.stats && data.mode === null) {
data.mode = data.stats.mode & 0777;
data.mode = data.stats.mode & 511;
} else if (data.mode === null) {
data.mode = isDir ? 0755 : 0644;
data.mode = isDir ? 493 : 420;
}

if (data.stats && data.date === null) {
@@ -357,17 +364,37 @@ Archiver.prototype.bulk = function(mappings) {

files.forEach(function(file){
var isExpandedPair = file.orig.expand || false;
var fileData = file.data || {};
var data = {};
var dataFunction = false;

if (typeof file.data === 'function') {
dataFunction = file.data;
} else if (typeof file.data === 'object') {
data = file.data;
}

file.src.forEach(function(filepath) {
var data = util._.extend({}, fileData);
data.name = isExpandedPair ? util.unixifyPath(file.dest) : util.unixifyPath(file.dest || '', filepath);
var entryData = util._.extend({}, data);
entryData.name = isExpandedPair ? util.unixifyPath(file.dest) : util.unixifyPath(file.dest || '', filepath);

if (entryData.name === '.') {
return;
}

try {
if (dataFunction) {
entryData = dataFunction(entryData);

if (data.name === '.') {
if (typeof entryData !== 'object') {
throw new Error('bulk: invalid data returned from custom function');
}
}
} catch(e) {
self.emit('error', e);
return;
}

self._append(filepath, data);
self._append(filepath, entryData);
});
});

@@ -393,7 +420,11 @@ Archiver.prototype.directory = function(dirpath, destpath, data) {
destpath = dirpath;
}

if (typeof data !== 'object') {
var dataFunction = false;
if (typeof data === 'function') {
dataFunction = data;
data = {};
} else if (typeof data !== 'object') {
data = {};
}

@@ -408,6 +439,19 @@ Archiver.prototype.directory = function(dirpath, destpath, data) {
entryData.name = util.sanitizePath(destpath, file.relative);
entryData.stats = file.stats;

try {
if (dataFunction) {
entryData = dataFunction(entryData);

if (typeof entryData !== 'object') {
throw new Error('directory: invalid data returned from custom function');
}
}
} catch(e) {
self.emit('error', e);
return;
}

self._append(file.path, entryData);
});
}
@@ -455,6 +499,7 @@ Archiver.prototype.finalize = function() {
return this;
};

// needs to be deprecated in 0.16/removed in 0.17
Archiver.prototype.setFormat = function(format) {
if (this._format) {
this.emit('error', new Error('format: archive format already set'));
@@ -466,6 +511,7 @@ Archiver.prototype.setFormat = function(format) {
return this;
};

// needs to be deprecated in 0.16/removed in 0.17
Archiver.prototype.setModule = function(module) {
if (this._state.aborted) {
this.emit('error', new Error('module: archive was aborted'));
@@ -485,4 +531,9 @@ Archiver.prototype.setModule = function(module) {

Archiver.prototype.pointer = function() {
return this._pointer;
};

Archiver.prototype.use = function(plugin) {
this._streams.push(plugin);
return this;
};
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "archiver",
"version": "0.14.4",
"version": "0.15.0",
"description": "a streaming interface for archive generation",
"homepage": "https://github.com/archiverjs/node-archiver",
"author": {
@@ -15,8 +15,9 @@
"url": "https://github.com/archiverjs/node-archiver/issues"
},
"license": "MIT",
"main": "lib/archiver.js",
"main": "index.js",
"files": [
"index.js",
"lib"
],
"engines": {
@@ -27,23 +28,23 @@
"bench": "node benchmark/simple/pack-zip.js"
},
"dependencies": {
"async": "~0.9.0",
"async": "~1.4.2",
"buffer-crc32": "~0.2.1",
"glob": "~4.3.0",
"glob": "~5.0.0",
"lazystream": "~0.1.0",
"lodash": "~3.2.0",
"lodash": "~3.10.0",
"readable-stream": "~1.0.26",
"tar-stream": "~1.1.0",
"tar-stream": "~1.2.1",
"zip-stream": "~0.5.0"
},
"devDependencies": {
"chai": "~2.0.0",
"mocha": "~2.1.0",
"rimraf": "~2.2.8",
"chai": "~3.2.0",
"mocha": "~2.2.5",
"rimraf": "~2.4.2",
"mkdirp": "~0.5.0",
"stream-bench": "~0.1.2",
"tar": "~1.0.3",
"yauzl": "~2.2.1"
"tar": "~2.1.1",
"yauzl": "~2.3.1"
},
"keywords": [
"archive",
Loading