Skip to content

Commit 0a2c38b

Browse files
authored
Merge pull request archiverjs#27 from garymathews/compat
Improve ZIP compatibility
2 parents e201893 + 37fbcf4 commit 0a2c38b

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/archivers/zip/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ util.getEightBytes = function(v) {
4949

5050
util.getShortBytes = function(v) {
5151
var buf = new Buffer(2);
52-
buf.writeUInt16LE(v, 0);
52+
buf.writeUInt16LE((v & 0xFFFF) >>> 0, 0);
5353

5454
return buf;
5555
};
@@ -60,7 +60,7 @@ util.getShortBytesValue = function(buf, offset) {
6060

6161
util.getLongBytes = function(v) {
6262
var buf = new Buffer(4);
63-
buf.writeUInt32LE(v, 0);
63+
buf.writeUInt32LE((v & 0xFFFFFFFF) >>> 0, 0);
6464

6565
return buf;
6666
};

lib/archivers/zip/zip-archive-entry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ var ZipArchiveEntry = module.exports = function(name) {
2626
this.method = -1;
2727

2828
this.name = null;
29-
this.size = -1;
30-
this.csize = -1;
29+
this.size = 0;
30+
this.csize = 0;
3131
this.gpb = new GeneralPurposeBit();
3232
this.crc = 0;
3333
this.time = -1;

lib/archivers/zip/zip-archive-output-stream.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ ZipArchiveOutputStream.prototype._appendBuffer = function(ae, source, callback)
8888
};
8989

9090
ZipArchiveOutputStream.prototype._appendStream = function(ae, source, callback) {
91-
ae.getGeneralPurposeBit().useDataDescriptor(true);
92-
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
91+
if (ae.getMethod() !== constants.METHOD_STORED) {
92+
ae.getGeneralPurposeBit().useDataDescriptor(true);
93+
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
94+
}
9395

9496
this._writeLocalFileHeader(ae);
9597

0 commit comments

Comments
 (0)