Skip to content

Commit 80e1e63

Browse files
committed
stored buffers now implemented. lots of other little things.
1 parent cb452fe commit 80e1e63

7 files changed

Lines changed: 283 additions & 109 deletions

File tree

lib/archivers/zip/constants.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
* https://github.com/ctalkington/node-compress-commons/blob/master/LICENSE-MIT
77
*/
88
module.exports = {
9-
ZERO_SHORT: new Buffer(Array(2)),
10-
ZERO_LONG: new Buffer(Array(4)),
9+
WORD: 4,
10+
DWORD: 8,
11+
EMPTY: new Buffer(0),
1112

12-
DATA_DESCRIPTOR_MIN_VERSION: 20,
13+
SHORT: 2,
14+
SHORT_MASK: 0xffff,
15+
SHORT_SHIFT: 16,
16+
SHORT_ZERO: new Buffer(Array(2)),
17+
LONG_ZERO: new Buffer(Array(4)),
1318

19+
DATA_DESCRIPTOR_MIN_VERSION: 20,
1420
INITIAL_VERSION: 10,
1521

1622
METHOD_STORED: 0,
@@ -19,20 +25,13 @@ module.exports = {
1925
PLATFORM_UNIX: 3,
2026
PLATFORM_FAT: 0,
2127

22-
SHORT_MASK: 0xffff,
23-
SHORT_SHIFT: 16,
24-
2528
SIG_LFH: 0x04034b50,
2629
SIG_DD: 0x08074b50,
2730
SIG_CFH: 0x02014b50,
2831
SIG_EOCD: 0x06054b50,
2932
SIG_ZIP64_EOCD: 0x06064B50,
3033
SIG_ZIP64_EOCD_LOC: 0x07064B50,
3134

32-
SHORT: 2,
33-
WORD: 4,
34-
DWORD: 8,
35-
3635
ZIP64_MIN_VERSION: 45,
3736
ZIP64_MAGIC_SHORT: 0xffff,
3837
ZIP64_MAGIC: 0xffffffff

lib/archivers/zip/general-purpose-bit.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ var GeneralPurposeBit = module.exports = function() {
2020
}
2121

2222
this.descriptor = false;
23-
this.encrpytion = false;
23+
this.encryption = false;
2424
this.language = false;
2525
this.numberOfShannonFanoTrees = 0;
26-
this.strongEncrpytion = false;
26+
this.strongEncryption = false;
2727
this.slidingDictionarySize = 0;
2828
};
2929

@@ -44,8 +44,8 @@ GeneralPurposeBit.prototype.parse = function(buf, offset) {
4444
gbp.useUTF8ForNames((flag & UFT8_NAMES_FLAG) !== 0);
4545
gbp.useStrongEncryption((flag & STRONG_ENCRYPTION_FLAG) !== 0);
4646
gbp.useEncryption((flag & ENCRYPTION_FLAG) !== 0);
47-
gbp.setSlidingDictionarySize = (flag & SLIDING_DICTIONARY_SIZE_FLAG) !== 0 ? 8192 : 4096;
48-
gbp.setNumberOfShannonFanoTrees = (flag & NUMBER_OF_SHANNON_FANO_TREES_FLAG) !== 0 ? 3 : 2;
47+
gbp.setSlidingDictionarySize((flag & SLIDING_DICTIONARY_SIZE_FLAG) !== 0 ? 8192 : 4096);
48+
gbp.setNumberOfShannonFanoTrees((flag & NUMBER_OF_SHANNON_FANO_TREES_FLAG) !== 0 ? 3 : 2);
4949

5050
return gbp;
5151
};
@@ -75,19 +75,19 @@ GeneralPurposeBit.prototype.usesDataDescriptor = function() {
7575
};
7676

7777
GeneralPurposeBit.prototype.useEncryption = function(b) {
78-
this.encrpytion = b;
78+
this.encryption = b;
7979
};
8080

8181
GeneralPurposeBit.prototype.usesEncryption = function() {
82-
return this.encrpytion;
82+
return this.encryption;
8383
};
8484

8585
GeneralPurposeBit.prototype.useStrongEncryption = function(b) {
86-
this.strongEncrpytion = b;
86+
this.strongEncryption = b;
8787
};
8888

8989
GeneralPurposeBit.prototype.usesStrongEncryption = function() {
90-
return this.strongEncrpytion;
90+
return this.strongEncryption;
9191
};
9292

9393
GeneralPurposeBit.prototype.useUTF8ForNames = function(b) {

lib/archivers/zip/headers.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ var ZipArchiveEntry = module.exports = function(name) {
2727
this.size = -1;
2828
this.csize = -1;
2929
this.gpb = new GeneralPurposeBit();
30-
this.crc = -1;
30+
this.crc = 0;
3131
this.time = -1;
3232

33+
this.minver = constants.INITIAL_VERSION;
3334
this.mode = -1;
34-
this.extra = 0;
35+
this.extra = null;
3536
this.exattr = 0;
3637
this.inattr = 0;
3738
this.comment = null;
@@ -43,8 +44,13 @@ var ZipArchiveEntry = module.exports = function(name) {
4344

4445
inherits(ZipArchiveEntry, ArchiveEntry);
4546

47+
ZipArchiveEntry.prototype.getCentralDirectoryExtra = function() {
48+
var extra = this.getExtra();
49+
return extra !== null ? extra : constants.EMPTY;
50+
};
51+
4652
ZipArchiveEntry.prototype.getComment = function() {
47-
return this.comment;
53+
return this.comment !== null ? this.comment : constants.EMPTY;
4854
};
4955

5056
ZipArchiveEntry.prototype.getCompressedSize = function() {
@@ -59,6 +65,10 @@ ZipArchiveEntry.prototype.getExternalAttributes = function() {
5965
return this.exattr;
6066
};
6167

68+
ZipArchiveEntry.prototype.getExtra = function() {
69+
return this.extra;
70+
};
71+
6272
ZipArchiveEntry.prototype.getGeneralPurposeBit = function() {
6373
return this.gpb;
6474
};
@@ -71,6 +81,11 @@ ZipArchiveEntry.prototype.getLastModifiedDate = function() {
7181
return this.getTime();
7282
};
7383

84+
ZipArchiveEntry.prototype.getLocalFileDataExtra = function() {
85+
var extra = this.getExtra();
86+
return extra !== null ? extra : constants.EMPTY;
87+
};
88+
7489
ZipArchiveEntry.prototype.getMethod = function() {
7590
return this.method;
7691
};
@@ -101,6 +116,10 @@ ZipArchiveEntry.prototype.getUnixMode = function() {
101116
return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK);
102117
};
103118

119+
ZipArchiveEntry.prototype.getVersionNeededToExtract = function() {
120+
return this.minver;
121+
};
122+
104123
ZipArchiveEntry.prototype.setComment = function(comment) {
105124
this.comment = comment;
106125
};
@@ -125,6 +144,10 @@ ZipArchiveEntry.prototype.setExternalAttributes = function(attr) {
125144
this.exattr = attr;
126145
};
127146

147+
ZipArchiveEntry.prototype.setExtra = function(extra) {
148+
this.extra = extra;
149+
};
150+
128151
ZipArchiveEntry.prototype.setGeneralPurposeBit = function(gpb) {
129152
if (!(gpb instanceof GeneralPurposeBit)) {
130153
throw new Error('invalid entry GeneralPurposeBit');
@@ -179,6 +202,10 @@ ZipArchiveEntry.prototype.setUnixMode = function(mode) {
179202
this.platform = constants.PLATFORM_UNIX;
180203
};
181204

205+
ZipArchiveEntry.prototype.setVersionNeededToExtract = function(minver) {
206+
this.minver = minver;
207+
};
208+
182209
ZipArchiveEntry.prototype.isDirectory = function() {
183210
return this.getName().slice(-1) === '/';
184211
};

0 commit comments

Comments
 (0)