node-stream-zip 1.6.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +44 -0
- package/node_stream_zip.js +42 -13
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Copyright (c) 2015 Antelle https://github.com/antelle
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
== dependency license: adm-zip ==
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2012 Another-D-Mention Software and other contributors,
|
|
25
|
+
http://www.another-d-mention.ro/
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
28
|
+
a copy of this software and associated documentation files (the
|
|
29
|
+
"Software"), to deal in the Software without restriction, including
|
|
30
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
31
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
32
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
33
|
+
the following conditions:
|
|
34
|
+
|
|
35
|
+
The above copyright notice and this permission notice shall be
|
|
36
|
+
included in all copies or substantial portions of the Software.
|
|
37
|
+
|
|
38
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
39
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
40
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
41
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
42
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
43
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
44
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/node_stream_zip.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license node-stream-zip | (c) 2015 Antelle | https://github.com/antelle/node-stream-zip/blob/master/
|
|
3
|
-
* Portions copyright https://github.com/cthackers/adm-zip | https://raw.githubusercontent.com/cthackers/adm-zip/master/
|
|
2
|
+
* @license node-stream-zip | (c) 2015 Antelle | https://github.com/antelle/node-stream-zip/blob/master/LICENSE
|
|
3
|
+
* Portions copyright https://github.com/cthackers/adm-zip | https://raw.githubusercontent.com/cthackers/adm-zip/master/LICENSE
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// region Deps
|
|
@@ -397,7 +397,7 @@ var StreamZip = function(config) {
|
|
|
397
397
|
if (err)
|
|
398
398
|
throw err;
|
|
399
399
|
var
|
|
400
|
-
data =
|
|
400
|
+
data = Buffer.alloc(entry.compressedSize),
|
|
401
401
|
bytesRead;
|
|
402
402
|
new FsRead(fd, data, 0, entry.compressedSize, dataOffset(entry), function(e, br) {
|
|
403
403
|
err = e;
|
|
@@ -431,7 +431,7 @@ var StreamZip = function(config) {
|
|
|
431
431
|
return callback('Entry is not file');
|
|
432
432
|
if (!fd)
|
|
433
433
|
return callback('Archive closed');
|
|
434
|
-
var buffer =
|
|
434
|
+
var buffer = Buffer.alloc(consts.LOCHDR);
|
|
435
435
|
new FsRead(fd, buffer, 0, buffer.length, entry.offset, function(err) {
|
|
436
436
|
if (err)
|
|
437
437
|
return callback(err);
|
|
@@ -658,6 +658,29 @@ CentralDirectoryZip64Header.prototype.read = function(data) {
|
|
|
658
658
|
var ZipEntry = function() {
|
|
659
659
|
};
|
|
660
660
|
|
|
661
|
+
function toBits(dec, size) {
|
|
662
|
+
var b = (dec >>> 0).toString(2);
|
|
663
|
+
while (b.length < size)
|
|
664
|
+
b = '0' + b;
|
|
665
|
+
return b.split('');
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function parseZipTime(timebytes, datebytes) {
|
|
669
|
+
var timebits = toBits(timebytes, 16);
|
|
670
|
+
var datebits = toBits(datebytes, 16);
|
|
671
|
+
|
|
672
|
+
var mt = {
|
|
673
|
+
h: parseInt(timebits.slice(0,5).join(''), 2),
|
|
674
|
+
m: parseInt(timebits.slice(5,11).join(''), 2),
|
|
675
|
+
s: parseInt(timebits.slice(11,16).join(''), 2) * 2,
|
|
676
|
+
Y: parseInt(datebits.slice(0,7).join(''), 2) + 1980,
|
|
677
|
+
M: parseInt(datebits.slice(7,11).join(''), 2),
|
|
678
|
+
D: parseInt(datebits.slice(11,16).join(''), 2),
|
|
679
|
+
};
|
|
680
|
+
var dt_str = [mt.Y, mt.M, mt.D].join('-') + ' ' + [mt.h, mt.m, mt.s].join(':') + ' GMT+0';
|
|
681
|
+
return new Date(dt_str).getTime();
|
|
682
|
+
}
|
|
683
|
+
|
|
661
684
|
ZipEntry.prototype.readHeader = function(data, offset) {
|
|
662
685
|
// data should be 46 bytes and start with "PK 01 02"
|
|
663
686
|
if (data.length < offset + consts.CENHDR || data.readUInt32LE(offset) != consts.CENSIG) {
|
|
@@ -672,7 +695,10 @@ ZipEntry.prototype.readHeader = function(data, offset) {
|
|
|
672
695
|
// compression method
|
|
673
696
|
this.method = data.readUInt16LE(offset + consts.CENHOW);
|
|
674
697
|
// modification time (2 bytes time, 2 bytes date)
|
|
675
|
-
|
|
698
|
+
var timebytes = data.readUInt16LE(offset + consts.CENTIM);
|
|
699
|
+
var datebytes = data.readUInt16LE(offset + consts.CENTIM + 2);
|
|
700
|
+
this.time = parseZipTime(timebytes, datebytes);
|
|
701
|
+
|
|
676
702
|
// uncompressed file crc-32 value
|
|
677
703
|
this.crc = data.readUInt32LE(offset + consts.CENCRC);
|
|
678
704
|
// compressed size
|
|
@@ -707,7 +733,10 @@ ZipEntry.prototype.readDataHeader = function(data) {
|
|
|
707
733
|
// compression method
|
|
708
734
|
this.method = data.readUInt16LE(consts.LOCHOW);
|
|
709
735
|
// modification time (2 bytes time ; 2 bytes date)
|
|
710
|
-
|
|
736
|
+
var timebytes = data.readUInt16LE(consts.LOCTIM);
|
|
737
|
+
var datebytes = data.readUInt16LE(consts.LOCTIM + 2);
|
|
738
|
+
this.time = parseZipTime(timebytes, datebytes);
|
|
739
|
+
|
|
711
740
|
// uncompressed file crc-32 value
|
|
712
741
|
this.crc = data.readUInt32LE(consts.LOCCRC) || this.crc;
|
|
713
742
|
// compressed size
|
|
@@ -838,7 +867,7 @@ FsRead.prototype.readCallback = function(sync, err, bytesRead) {
|
|
|
838
867
|
|
|
839
868
|
var FileWindowBuffer = function(fd) {
|
|
840
869
|
this.position = 0;
|
|
841
|
-
this.buffer =
|
|
870
|
+
this.buffer = Buffer.alloc(0);
|
|
842
871
|
|
|
843
872
|
var fsOp = null;
|
|
844
873
|
|
|
@@ -850,14 +879,14 @@ var FileWindowBuffer = function(fd) {
|
|
|
850
879
|
this.read = function(pos, length, callback) {
|
|
851
880
|
this.checkOp();
|
|
852
881
|
if (this.buffer.length < length)
|
|
853
|
-
this.buffer =
|
|
882
|
+
this.buffer = Buffer.alloc(length);
|
|
854
883
|
this.position = pos;
|
|
855
884
|
fsOp = new FsRead(fd, this.buffer, 0, length, this.position, callback).read();
|
|
856
885
|
};
|
|
857
886
|
|
|
858
887
|
this.expandLeft = function(length, callback) {
|
|
859
888
|
this.checkOp();
|
|
860
|
-
this.buffer = Buffer.concat([
|
|
889
|
+
this.buffer = Buffer.concat([Buffer.alloc(length), this.buffer]);
|
|
861
890
|
this.position -= length;
|
|
862
891
|
if (this.position < 0)
|
|
863
892
|
this.position = 0;
|
|
@@ -867,7 +896,7 @@ var FileWindowBuffer = function(fd) {
|
|
|
867
896
|
this.expandRight = function(length, callback) {
|
|
868
897
|
this.checkOp();
|
|
869
898
|
var offset = this.buffer.length;
|
|
870
|
-
this.buffer = Buffer.concat([this.buffer,
|
|
899
|
+
this.buffer = Buffer.concat([this.buffer, Buffer.alloc(length)]);
|
|
871
900
|
fsOp = new FsRead(fd, this.buffer, offset, length, this.position + offset, callback).read();
|
|
872
901
|
};
|
|
873
902
|
|
|
@@ -899,7 +928,7 @@ var EntryDataReaderStream = function(fd, offset, length) {
|
|
|
899
928
|
util.inherits(EntryDataReaderStream, stream.Readable);
|
|
900
929
|
|
|
901
930
|
EntryDataReaderStream.prototype._read = function(n) {
|
|
902
|
-
var buffer =
|
|
931
|
+
var buffer = Buffer.alloc(Math.min(n, this.length - this.pos));
|
|
903
932
|
if (buffer.length) {
|
|
904
933
|
fs.read(this.fd, buffer, 0, buffer.length, this.offset + this.pos, this.readCallback);
|
|
905
934
|
} else {
|
|
@@ -967,7 +996,7 @@ CrcVerify.prototype.data = function(data) {
|
|
|
967
996
|
this.state.crc = crc;
|
|
968
997
|
this.state.size += data.length;
|
|
969
998
|
if (this.state.size >= this.size) {
|
|
970
|
-
var buf =
|
|
999
|
+
var buf = Buffer.alloc(4);
|
|
971
1000
|
buf.writeInt32LE(~this.state.crc & 0xffffffff, 0);
|
|
972
1001
|
crc = buf.readUInt32LE(0);
|
|
973
1002
|
if (crc !== this.crc)
|
|
@@ -981,7 +1010,7 @@ CrcVerify.getCrcTable = function() {
|
|
|
981
1010
|
var crcTable = CrcVerify.crcTable;
|
|
982
1011
|
if (!crcTable) {
|
|
983
1012
|
CrcVerify.crcTable = crcTable = [];
|
|
984
|
-
var b =
|
|
1013
|
+
var b = Buffer.alloc(4);
|
|
985
1014
|
for (var n = 0; n < 256; n++) {
|
|
986
1015
|
var c = n;
|
|
987
1016
|
for (var k = 8; --k >= 0; )
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-stream-zip",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "node.js library for reading and extraction of ZIP archives",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zip",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"files": [
|
|
19
|
+
"LICENSE",
|
|
19
20
|
"node_stream_zip.js"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
@@ -30,6 +31,6 @@
|
|
|
30
31
|
"node": ">=0.10.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"nodeunit": "^0.
|
|
34
|
+
"nodeunit": "^0.11.3"
|
|
34
35
|
}
|
|
35
36
|
}
|