compress-commons
Advanced tools
Comparing version 0.1.6 to 0.2.0
@@ -22,2 +22,7 @@ /** | ||
this.offset = 0; | ||
this._archive = { | ||
finish: false, | ||
finished: false, | ||
processing: false | ||
}; | ||
}; | ||
@@ -45,3 +50,3 @@ | ||
ArchiveOutputStream.prototype._setDefaults = function(ae) { | ||
ArchiveOutputStream.prototype._normalizeEntry = function(ae) { | ||
// scaffold only | ||
@@ -77,3 +82,3 @@ }; | ||
this._archive.processing = true; | ||
this._setDefaults(ae); | ||
this._normalizeEntry(ae); | ||
this._entry = ae; | ||
@@ -80,0 +85,0 @@ |
@@ -17,6 +17,9 @@ /** | ||
SHORT_ZERO: new Buffer(Array(2)), | ||
LONG: 4, | ||
LONG_ZERO: new Buffer(Array(4)), | ||
DATA_DESCRIPTOR_MIN_VERSION: 20, | ||
INITIAL_VERSION: 10, | ||
MIN_VERSION_INITIAL: 10, | ||
MIN_VERSION_DATA_DESCRIPTOR: 20, | ||
MIN_VERSION_ZIP64: 45, | ||
VERSION_MADEBY: 45, | ||
@@ -36,5 +39,5 @@ METHOD_STORED: 0, | ||
ZIP64_MIN_VERSION: 45, | ||
ZIP64_MAGIC_SHORT: 0xffff, | ||
ZIP64_MAGIC: 0xffffffff, | ||
ZIP64_EXTRA_ID: 0x0001, | ||
@@ -41,0 +44,0 @@ ZLIB_NO_COMPRESSION: 0, |
@@ -8,2 +8,3 @@ /** | ||
*/ | ||
var Int64 = require('node-int64'); | ||
var util = module.exports = {}; | ||
@@ -48,2 +49,14 @@ | ||
util.getEightBytes = function(v) { | ||
var buf = new Buffer(8); | ||
var i64 = new Int64(v); | ||
// BE to LE | ||
for(i = 0; i < 8; i++) { | ||
buf[i] = i64.buffer[7 - i]; | ||
} | ||
return buf; | ||
}; | ||
util.getShortBytes = function(v) { | ||
@@ -50,0 +63,0 @@ var buf = new Buffer(2); |
@@ -33,3 +33,3 @@ /** | ||
this.minver = constants.INITIAL_VERSION; | ||
this.minver = constants.MIN_VERSION_INITIAL; | ||
this.mode = -1; | ||
@@ -224,2 +224,6 @@ this.extra = null; | ||
return this.getName().slice(-1) === '/'; | ||
}; | ||
ZipArchiveEntry.prototype.isZip64 = function() { | ||
return this.csize > constants.ZIP64_MAGIC || this.size > constants.ZIP64_MAGIC; | ||
}; |
@@ -26,4 +26,3 @@ /** | ||
options = this.options = options || {}; | ||
options.zlib = this._zlibDefaults(options.zlib); | ||
options = this.options = this._defaults(options); | ||
@@ -46,6 +45,9 @@ ArchiveOutputStream.call(this, options); | ||
ZipArchiveOutputStream.prototype._afterAppend = function(zae) { | ||
this._entries.push(zae); | ||
this._writeDataDescriptor(zae); | ||
ZipArchiveOutputStream.prototype._afterAppend = function(ae) { | ||
this._entries.push(ae); | ||
if (ae.getGeneralPurposeBit().usesDataDescriptor()) { | ||
this._writeDataDescriptor(ae); | ||
} | ||
this._archive.processing = false; | ||
@@ -90,2 +92,3 @@ this._entry = null; | ||
ae.getGeneralPurposeBit().useDataDescriptor(true); | ||
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR); | ||
@@ -98,2 +101,18 @@ this._writeLocalFileHeader(ae); | ||
ZipArchiveOutputStream.prototype._defaults = function(o) { | ||
if (typeof o !== 'object') { | ||
o = {}; | ||
} | ||
if (typeof o.zlib !== 'object') { | ||
o.zlib = {}; | ||
} | ||
if (typeof o.zlib.level !== 'number') { | ||
o.zlib.level = constants.ZLIB_BEST_SPEED; | ||
} | ||
return o; | ||
}; | ||
ZipArchiveOutputStream.prototype._finish = function() { | ||
@@ -108,2 +127,6 @@ this._archive.centralOffset = this.offset; | ||
if (this.isZip64()) { | ||
this._writeCentralDirectoryZip64(); | ||
} | ||
this._writeCentralDirectoryEnd(); | ||
@@ -117,3 +140,3 @@ | ||
ZipArchiveOutputStream.prototype._setDefaults = function(ae) { | ||
ZipArchiveOutputStream.prototype._normalizeEntry = function(ae) { | ||
if (ae.getMethod() === -1) { | ||
@@ -125,3 +148,3 @@ ae.setMethod(constants.METHOD_DEFLATED); | ||
ae.getGeneralPurposeBit().useDataDescriptor(true); | ||
ae.setVersionNeededToExtract(constants.DATA_DESCRIPTOR_MIN_VERSION); | ||
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR); | ||
} | ||
@@ -161,2 +184,12 @@ | ||
ZipArchiveOutputStream.prototype._writeCentralDirectoryEnd = function() { | ||
var records = this._entries.length; | ||
var size = this._archive.centralLength; | ||
var offset = this._archive.centralOffset; | ||
if (this.isZip64()) { | ||
records = constants.ZIP64_MAGIC_SHORT; | ||
size = constants.ZIP64_MAGIC; | ||
offset = constants.ZIP64_MAGIC; | ||
} | ||
// signature | ||
@@ -170,8 +203,8 @@ this.write(zipUtil.getLongBytes(constants.SIG_EOCD)); | ||
// number of entries | ||
this.write(zipUtil.getShortBytes(this._entries.length)); | ||
this.write(zipUtil.getShortBytes(this._entries.length)); | ||
this.write(zipUtil.getShortBytes(records)); | ||
this.write(zipUtil.getShortBytes(records)); | ||
// length and location of CD | ||
this.write(zipUtil.getLongBytes(this._archive.centralLength)); | ||
this.write(zipUtil.getLongBytes(this._archive.centralOffset)); | ||
this.write(zipUtil.getLongBytes(size)); | ||
this.write(zipUtil.getLongBytes(offset)); | ||
@@ -185,2 +218,43 @@ // archive comment | ||
ZipArchiveOutputStream.prototype._writeCentralDirectoryZip64 = function() { | ||
// signature | ||
this.write(constants.SIG_ZIP64_EOCD); | ||
// size of the ZIP64 EOCD record | ||
this.write(zipUtil.getEightBytes((constants.SHORT * 2) + (constants.LONG * 2) + (8 * 4))); | ||
// version made by | ||
this.write(zipUtil.getShortBytes((ae.getPlatform() << 8) | constants.VERSION_MADEBY)); | ||
// version to extract | ||
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract())); | ||
// disk numbers | ||
this.write(constants.LONG_ZERO); | ||
this.write(constants.LONG_ZERO); | ||
// number of entries | ||
this.write(zipUtil.getEightBytes(this._entries.length)); | ||
this.write(zipUtil.getEightBytes(this._entries.length)); | ||
// length and location of CD | ||
this.write(zipUtil.getEightBytes(this._archive.centralLength)); | ||
this.write(zipUtil.getEightBytes(this._archive.centralOffset)); | ||
// extensible data sector | ||
// not implemented at this time | ||
// end of central directory locator | ||
this.write(costants.SIG_ZIP64_EOCD_LOC); | ||
// disk number holding the ZIP64 EOCD record | ||
this.write(constants.LONG_ZERO); | ||
// relative offset of the ZIP64 EOCD record | ||
this.write(zipUtil.getEightBytes(this._archive.centralOffset + this._archive.centralLength)); | ||
// total number of disks | ||
this.write(this.getLongBytes(1)); | ||
}; | ||
ZipArchiveOutputStream.prototype._writeCentralFileHeader = function(ae) { | ||
@@ -191,2 +265,20 @@ var gpb = ae.getGeneralPurposeBit(); | ||
var size = ae.getSize(); | ||
var compressedSize = ae.getCompressedSize(); | ||
if (ae.isZip64() || offsets.file > constants.ZIP64_MAGIC) { | ||
size = constants.ZIP64_MAGIC; | ||
compressedSize = constants.ZIP64_MAGIC; | ||
ae.setVersionNeededToExtract(constants.MIN_VERSION_ZIP64); | ||
var extraBuf = new Buffer(28); | ||
extraBuf.write(zipUtil.getShortBytes(constants.ZIP64_EXTRA_ID)); | ||
extraBuf.write(zipUtil.getShortBytes(24)); | ||
extraBuf.write(zipUtil.getEightBytes(ae.getSize())); | ||
extraBuf.write(zipUtil.getEightBytes(ae.getCompressedSize())); | ||
extraBuf.write(zipUtil.getEightBytes(offsets.file)); | ||
ae.setExtra(extraBuf); | ||
} | ||
// signature | ||
@@ -196,8 +288,7 @@ this.write(zipUtil.getLongBytes(constants.SIG_CFH)); | ||
// version made by | ||
this.write(zipUtil.getShortBytes( | ||
(ae.getPlatform() << 8) | constants.DATA_DESCRIPTOR_MIN_VERSION | ||
)); | ||
this.write(zipUtil.getShortBytes((ae.getPlatform() << 8) | constants.VERSION_MADEBY)); | ||
// version to extract and general bit flag | ||
this._writeVersionGeneral(ae); | ||
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract())); | ||
this.write(gpb.encode()); | ||
@@ -214,4 +305,4 @@ // compression method | ||
// sizes | ||
this.write(zipUtil.getLongBytes(ae.getCompressedSize())); | ||
this.write(zipUtil.getLongBytes(ae.getSize())); | ||
this.write(zipUtil.getLongBytes(compressedSize)); | ||
this.write(zipUtil.getLongBytes(size)); | ||
@@ -246,3 +337,7 @@ var name = ae.getName(); | ||
// relative offset of LFH | ||
this.write(zipUtil.getLongBytes(offsets.file)); | ||
if (offsets.file > constants.ZIP64_MAGIC) { | ||
this.write(zipUtil.getLongBytes(constants.ZIP64_MAGIC)); | ||
} else { | ||
this.write(zipUtil.getLongBytes(offsets.file)); | ||
} | ||
@@ -260,6 +355,2 @@ // name | ||
ZipArchiveOutputStream.prototype._writeDataDescriptor = function(ae) { | ||
if (!ae.getGeneralPurposeBit().usesDataDescriptor()) { | ||
return; | ||
} | ||
// signature | ||
@@ -272,4 +363,9 @@ this.write(zipUtil.getLongBytes(constants.SIG_DD)); | ||
// sizes | ||
this.write(zipUtil.getLongBytes(ae.getCompressedSize())); | ||
this.write(zipUtil.getLongBytes(ae.getSize())); | ||
if (ae.isZip64()) { | ||
this.write(zipUtil.getEightBytes(ae.getCompressedSize())); | ||
this.write(zipUtil.getEightBytes(ae.getSize())); | ||
} else { | ||
this.write(zipUtil.getLongBytes(ae.getCompressedSize())); | ||
this.write(zipUtil.getLongBytes(ae.getSize())); | ||
} | ||
}; | ||
@@ -283,2 +379,7 @@ | ||
if (ae.isZip64()) { | ||
gpb.useDataDescriptor(true); | ||
ae.setVersionNeededToExtract(constants.MIN_VERSION_ZIP64); | ||
} | ||
if (gpb.usesUTF8ForNames()) { | ||
@@ -294,3 +395,4 @@ name = new Buffer(name); | ||
// version to extract and general bit flag | ||
this._writeVersionGeneral(ae); | ||
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract())); | ||
this.write(gpb.encode()); | ||
@@ -305,4 +407,4 @@ // compression method | ||
if (ae.getGeneralPurposeBit().usesDataDescriptor()) { | ||
// zero fill and set later | ||
// crc32 checksum and sizes | ||
if (gpb.usesDataDescriptor()) { | ||
this.write(constants.LONG_ZERO); | ||
@@ -312,3 +414,2 @@ this.write(constants.LONG_ZERO); | ||
} else { | ||
// crc32 checksum and sizes | ||
this.write(zipUtil.getLongBytes(ae.getCrc())); | ||
@@ -334,25 +435,12 @@ this.write(zipUtil.getLongBytes(ae.getCompressedSize())); | ||
ZipArchiveOutputStream.prototype._writeVersionGeneral = function(ae) { | ||
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract())); | ||
this.write(ae.getGeneralPurposeBit().encode()); | ||
ZipArchiveOutputStream.prototype.getComment = function(comment) { | ||
return this._archive.comment !== null ? this._archive.comment : ''; | ||
}; | ||
ZipArchiveOutputStream.prototype._zlibDefaults = function(o) { | ||
if (typeof o !== 'object') { | ||
o = {}; | ||
} | ||
if (typeof o.level !== 'number') { | ||
o.level = constants.ZLIB_BEST_SPEED; | ||
} | ||
return o; | ||
ZipArchiveOutputStream.prototype.isZip64 = function() { | ||
return this._entries.length > constants.ZIP64_MAGIC_SHORT || this._archive.centralLength > constants.ZIP64_MAGIC || this._archive.centralOffset > constants.ZIP64_MAGIC; | ||
}; | ||
ZipArchiveOutputStream.prototype.getComment = function(comment) { | ||
return this._archive.comment !== null ? this._archive.comment : ''; | ||
}; | ||
ZipArchiveOutputStream.prototype.setComment = function(comment) { | ||
this._archive.comment = comment; | ||
}; |
{ | ||
"name": "compress-commons", | ||
"version": "0.1.6", | ||
"description": "a library that defines a common interface for working with archives within node", | ||
"version": "0.2.0", | ||
"description": "a library that defines a common interface for working with archive formats within node", | ||
"homepage": "https://github.com/ctalkington/node-compress-commons", | ||
@@ -37,2 +37,3 @@ "author": { | ||
"crc32-stream": "~0.3.1", | ||
"node-int64": "~0.3.0", | ||
"readable-stream": "~1.0.26" | ||
@@ -39,0 +40,0 @@ }, |
@@ -1,4 +0,4 @@ | ||
# Compress Commons v0.1.6 [![Build Status](https://travis-ci.org/ctalkington/node-compress-commons.svg?branch=master)](https://travis-ci.org/ctalkington/node-compress-commons) | ||
# Compress Commons v0.2.0 [![Build Status](https://travis-ci.org/ctalkington/node-compress-commons.svg?branch=master)](https://travis-ci.org/ctalkington/node-compress-commons) | ||
Compress Commons is a library that defines a common interface for working with archives within node. | ||
Compress Commons is a library that defines a common interface for working with archive formats within node. | ||
@@ -5,0 +5,0 @@ [![NPM](https://nodei.co/npm/compress-commons.png)](https://nodei.co/npm/compress-commons/) |
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
32356
837
4
+ Addednode-int64@~0.3.0
+ Addednode-int64@0.3.3(transitive)