Comparing version 0.14.4 to 0.15.0-1
@@ -8,15 +8,24 @@ /** | ||
*/ | ||
var async = require('async'); | ||
var fs = require('fs'); | ||
var util = require('./util'); | ||
// built-in plugins | ||
var pjson = require('archiver-json'); | ||
var ptar = require('archiver-tar'); | ||
var pzip = require('archiver-zip'); | ||
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, { | ||
@@ -47,2 +56,14 @@ highWaterMark: 1024 * 1024, | ||
}; | ||
this._streams = []; | ||
if (format === 'zip') { | ||
// this.use(pzip()); | ||
} else if (format === 'tar') { | ||
// this.use(ptar()); | ||
} else if (format === 'json') { | ||
this.use(pjson()); | ||
} else { | ||
this.emit(error, new Error('no format plugin')); | ||
} | ||
}; | ||
@@ -195,8 +216,9 @@ | ||
// 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; | ||
} | ||
@@ -363,13 +385,33 @@ | ||
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 (data.name === '.') { | ||
if (entryData.name === '.') { | ||
return; | ||
} | ||
self._append(filepath, data); | ||
try { | ||
if (dataFunction) { | ||
entryData = dataFunction(entryData); | ||
if (typeof entryData !== 'object') { | ||
throw new Error('bulk: invalid data returned from custom function'); | ||
} | ||
} | ||
} catch(e) { | ||
self.emit('error', e); | ||
return; | ||
} | ||
self._append(filepath, entryData); | ||
}); | ||
@@ -400,4 +442,8 @@ }); | ||
if (typeof data !== 'object') { | ||
var dataFunction = false; | ||
if (typeof data === 'function') { | ||
dataFunction = data; | ||
data = {}; | ||
} else if (typeof data !== 'object') { | ||
data = {}; | ||
} | ||
@@ -416,2 +462,15 @@ | ||
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); | ||
@@ -464,2 +523,3 @@ }); | ||
// needs to be deprecated | ||
Archiver.prototype.setFormat = function(format) { | ||
@@ -476,2 +536,3 @@ if (this._format) { | ||
// needs to be deprecated | ||
Archiver.prototype.setModule = function(module) { | ||
@@ -496,2 +557,7 @@ if (this._state.aborted) { | ||
return this._pointer; | ||
}; | ||
Archiver.prototype.use = function(plugin) { | ||
this._streams.push(plugin); | ||
return this; | ||
}; |
{ | ||
"name": "archiver", | ||
"version": "0.14.4", | ||
"version": "0.15.0-1", | ||
"description": "a streaming interface for archive generation", | ||
@@ -18,4 +18,5 @@ "homepage": "https://github.com/archiverjs/node-archiver", | ||
"license": "MIT", | ||
"main": "lib/archiver.js", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"lib" | ||
@@ -31,2 +32,5 @@ ], | ||
"dependencies": { | ||
"archiver-json": "~0.1.0", | ||
"archiver-tar": "~0.1.0", | ||
"archiver-zip": "~0.1.0", | ||
"async": "~0.9.0", | ||
@@ -33,0 +37,0 @@ "buffer-crc32": "~0.2.1", |
@@ -1,2 +0,2 @@ | ||
# 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-1 [![Build Status](https://travis-ci.org/archiverjs/node-archiver.svg?branch=master)](https://travis-ci.org/archiverjs/node-archiver) | ||
@@ -13,18 +13,19 @@ a streaming interface for archive generation | ||
You can also use `npm install https://github.com/archiverjs/node-archiver/archive/master.tar.gz` to test upcoming versions. | ||
## Usage | ||
## Archiver | ||
```js | ||
var archiver = require('archiver'); | ||
var archive = archiver.create('zip', {}); // or archiver('zip', {}); | ||
``` | ||
#### create(format, options) | ||
## API | ||
Creates an Archiver instance based on the format (zip, tar, etc) passed. Parameters can be passed directly to `Archiver` constructor for convenience. | ||
#### Transform | ||
#### registerFormat(format, module) | ||
Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) methods. | ||
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. | ||
#### create(format, options) | ||
### Instance Methods | ||
Creates an Archiver instance based on the format (zip, tar, etc) passed. Parameters can be passed directly to `Archiver` constructor for convenience. | ||
Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) methods. | ||
#### abort() | ||
@@ -65,2 +66,6 @@ | ||
{ src: ['mydir/**'], data: { date: new Date() } }, | ||
{ src: ['mydir/**'], data: function(data) { | ||
data.date = new Date(); | ||
return data; | ||
}}, | ||
{ expand: true, cwd: 'mydir', src: ['**'], dest: 'newdir' } | ||
@@ -70,2 +75,4 @@ ]); | ||
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). | ||
@@ -86,4 +93,10 @@ | ||
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) | ||
@@ -107,2 +120,6 @@ | ||
#### use(plugin) | ||
Add a plugin to the middleware stack. Currently this is designed for passing the module to use (replaces registerFormat/setFormat/setModule) | ||
## Events | ||
@@ -109,0 +126,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40012
946
232
11
+ Addedarchiver-json@~0.1.0
+ Addedarchiver-tar@~0.1.0
+ Addedarchiver-zip@~0.1.0