Comparing version 0.4.1 to 0.4.2
@@ -12,3 +12,3 @@ /** | ||
var inherits = require('util').inherits; | ||
var Readable = require('stream').Readable || require('readable-stream'); | ||
var Transform = require('stream').Transform || require('readable-stream/transform'); | ||
@@ -18,3 +18,3 @@ var util = require('../util'); | ||
var Archiver = module.exports = function(options) { | ||
Readable.call(this, options); | ||
Transform.call(this, options); | ||
@@ -33,14 +33,14 @@ this.archiver = { | ||
inherits(Archiver, Readable); | ||
inherits(Archiver, Transform); | ||
Archiver.prototype._read = function(n, callback) { | ||
this._processQueue(); | ||
Archiver.prototype._transform = function(chunk, encoding, callback) { | ||
callback(null, chunk); | ||
}; | ||
Archiver.prototype._push = function(data) { | ||
this.push(data); | ||
if (data) { | ||
this.archiver.pointer += data.length; | ||
} | ||
return this.push(data); | ||
}; | ||
@@ -69,3 +69,3 @@ | ||
this.archiver.eof = true; | ||
this._push(null); | ||
this.end(); | ||
} else if (this.archiver.finalize && this.archiver.queue.length === 0) { | ||
@@ -77,3 +77,8 @@ this._finalize(); | ||
Archiver.prototype._finalize = function() { | ||
this.emit('error', new Error('method not implemented')); | ||
this.archiver.finalize = false; | ||
this.archiver.finalized = true; | ||
this._processQueue(); | ||
//this.emit('error', new Error('method not implemented')); | ||
}; | ||
@@ -84,3 +89,3 @@ | ||
source = new Buffer(source, 'utf-8'); | ||
} else if (source && source.pause) { | ||
} else if (source && typeof source.pause === 'function' && !source._readableState) { | ||
source.pause(); | ||
@@ -87,0 +92,0 @@ } |
@@ -29,2 +29,10 @@ /** | ||
tarArchiver.prototype._flush = function(callback) { | ||
var endBytes = this.blockSize - (this.archiver.pointer % this.blockSize); | ||
this._push(util.cleanBuffer(endBytes)); | ||
callback(); | ||
}; | ||
tarArchiver.prototype._processFile = function(source, data, callback) { | ||
@@ -79,3 +87,3 @@ var self = this; | ||
self._push(headers.file.toBuffer(file)); | ||
self._push(headers.encode('file', file)); | ||
self._push(sourceBuffer); | ||
@@ -107,11 +115,2 @@ self._push(util.cleanBuffer(extraBytes)); | ||
} | ||
}; | ||
tarArchiver.prototype._finalize = function() { | ||
var endBytes = this.blockSize - (this.archiver.pointer % this.blockSize); | ||
this.archiver.finalize = false; | ||
this.archiver.finalized = true; | ||
this._push(util.cleanBuffer(endBytes)); | ||
}; |
@@ -15,2 +15,3 @@ /** | ||
var DeflateRawChecksum = require('../util/DeflateRawChecksum'); | ||
var ChecksumStream = require('../util/ChecksumStream'); | ||
@@ -31,2 +32,8 @@ var zipArchiver = module.exports = function(options) { | ||
zipArchiver.prototype._flush = function(callback) { | ||
this._push(this._buildCentralDirectory()); | ||
callback(); | ||
}; | ||
zipArchiver.prototype._buildCentralDirectory = function() { | ||
@@ -47,3 +54,3 @@ var files = this.archiver.files; | ||
centralDirectoryBuffer = headers.centralHeader.toBuffer(file); | ||
centralDirectoryBuffer = headers.encode('centralHeader', file); | ||
centralDirectoryBuffers.push(centralDirectoryBuffer); | ||
@@ -63,3 +70,3 @@ ptr += centralDirectoryBuffer.length; | ||
var centralDirectoryFooterBuffer = headers.centralFooter.toBuffer(centralDirectoryFooterData); | ||
var centralDirectoryFooterBuffer = headers.encode('centralFooter', centralDirectoryFooterData); | ||
@@ -107,5 +114,6 @@ centralDirectoryBuffers.push(centralDirectoryFooterBuffer); | ||
file.offset = self.archiver.pointer; | ||
self._push(headers.file.toBuffer(file)); | ||
self._push(headers.encode('file', file)); | ||
var deflate; | ||
var checksumr; | ||
@@ -117,6 +125,2 @@ if (file.store === false) { | ||
deflate.on('data', function(chunk) { | ||
self._push(chunk); | ||
}); | ||
deflate.on('end', function() { | ||
@@ -126,8 +130,27 @@ file.crc32 = deflate.digest; | ||
file.compressedSize = deflate.compressedSize; | ||
self.archiver.pointer += deflate.compressedSize; | ||
onend(); | ||
}); | ||
deflate.pipe(self, { end: false }); | ||
} else { | ||
checksumr = new ChecksumStream(); | ||
checksumr.on('error', callback); | ||
checksumr.on('end', function () { | ||
file.uncompressedSize = checksumr.rawSize; | ||
file.compressedSize = checksumr.rawSize; | ||
file.crc32 = checksumr.digest; | ||
self.archiver.pointer += checksumr.rawSize; | ||
onend(); | ||
}); | ||
checksumr.pipe(self, { end: false }); | ||
} | ||
function onend() { | ||
self._push(headers.descriptor.toBuffer(file)); | ||
self._push(headers.encode('fileDescriptor', file)); | ||
@@ -154,17 +177,3 @@ self.archiver.files.push(file); | ||
if (file.store) { | ||
var checksum = util.crc32.createCRC32(); | ||
source.on('error', callback); | ||
source.on('data', function(chunk) { | ||
checksum.update(chunk); | ||
file.uncompressedSize += chunk.length; | ||
self._push(chunk); | ||
}); | ||
source.on('end', function () { | ||
file.compressedSize = file.uncompressedSize; | ||
file.crc32 = checksum.digest(); | ||
onend(); | ||
}); | ||
source.pipe(checksumr); | ||
} else { | ||
@@ -174,3 +183,3 @@ source.pipe(deflate); | ||
if (typeof source.resume === 'function') { | ||
if (!source._readableState && typeof source.resume === 'function') { | ||
source.resume(); | ||
@@ -181,9 +190,2 @@ } | ||
} | ||
}; | ||
zipArchiver.prototype._finalize = function() { | ||
this.archiver.finalize = false; | ||
this.archiver.finalized = true; | ||
this._push(this._buildCentralDirectory()); | ||
}; |
@@ -11,3 +11,3 @@ /** | ||
var headers = module.exports = {}; | ||
var headers = {}; | ||
@@ -90,2 +90,18 @@ headers.file = { | ||
} | ||
}; | ||
var encode = exports.encode = function(type, data) { | ||
if (typeof headers[type].toBuffer === 'function') { | ||
return headers[type].toBuffer(data); | ||
} else { | ||
return false; | ||
} | ||
}; | ||
var decode = exports.decode = function(type, data) { | ||
if (typeof headers[type].toObject === 'function') { | ||
return headers[type].toObject(data); | ||
} else { | ||
return false; | ||
} | ||
}; |
@@ -9,3 +9,3 @@ /** | ||
var headers = module.exports = {}; | ||
var headers = {}; | ||
@@ -63,3 +63,3 @@ headers.file = { | ||
headers.descriptor = { | ||
headers.fileDescriptor = { | ||
fields: [ | ||
@@ -201,2 +201,18 @@ {'field': 'signature', 'length': 4, 'type': 'UInt32LE', 'default': 0x08074b50}, | ||
} | ||
}; | ||
var encode = exports.encode = function(type, data) { | ||
if (typeof headers[type].toBuffer === 'function') { | ||
return headers[type].toBuffer(data); | ||
} else { | ||
return false; | ||
} | ||
}; | ||
var decode = exports.decode = function(type, data) { | ||
if (typeof headers[type].toObject === 'function') { | ||
return headers[type].toObject(data); | ||
} else { | ||
return false; | ||
} | ||
}; |
@@ -48,3 +48,3 @@ /** | ||
if (typeof stream.resume === 'function') { | ||
if (!stream._readableState && typeof stream.resume === 'function') { | ||
stream.resume(); | ||
@@ -51,0 +51,0 @@ } |
{ | ||
"name": "archiver", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Creates Archives (ZIP) via Node Streams.", | ||
@@ -32,3 +32,3 @@ "homepage": "https://github.com/ctalkington/node-archiver", | ||
"dependencies": { | ||
"readable-stream": "~0.3.1" | ||
"readable-stream": "~1.0.2" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
@@ -1,2 +0,2 @@ | ||
# Archiver v0.4.1 [![Build Status](https://secure.travis-ci.org/ctalkington/node-archiver.png?branch=master)](http://travis-ci.org/ctalkington/node-archiver) | ||
# Archiver v0.4.2 [![Build Status](https://secure.travis-ci.org/ctalkington/node-archiver.png?branch=master)](http://travis-ci.org/ctalkington/node-archiver) | ||
@@ -73,3 +73,3 @@ Creates Archives (Zip, Tar) via Node Streams. Depends on Node's build-in zlib module for compression available since version 0.6.3. | ||
## Tar (beta) | ||
## Tar | ||
@@ -76,0 +76,0 @@ ### Options |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
54314
31
1302
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedstring_decoder@0.10.31(transitive)
- Removedreadable-stream@0.3.1(transitive)
Updatedreadable-stream@~1.0.2