1 | var Utils = require("../util"),
|
2 | Constants = Utils.Constants;
|
3 |
|
4 |
|
5 | module.exports = function () {
|
6 | var _volumeEntries = 0,
|
7 | _totalEntries = 0,
|
8 | _size = 0,
|
9 | _offset = 0,
|
10 | _commentLength = 0;
|
11 |
|
12 | return {
|
13 | get diskEntries () { return _volumeEntries },
|
14 | set diskEntries (/*Number*/val) { _volumeEntries = _totalEntries = val; },
|
15 |
|
16 | get totalEntries () { return _totalEntries },
|
17 | set totalEntries (/*Number*/val) { _totalEntries = _volumeEntries = val; },
|
18 |
|
19 | get size () { return _size },
|
20 | set size (/*Number*/val) { _size = val; },
|
21 |
|
22 | get offset () { return _offset },
|
23 | set offset (/*Number*/val) { _offset = val; },
|
24 |
|
25 | get commentLength () { return _commentLength },
|
26 | set commentLength (/*Number*/val) { _commentLength = val; },
|
27 |
|
28 | get mainHeaderSize () {
|
29 | return Constants.ENDHDR + _commentLength;
|
30 | },
|
31 |
|
32 | loadFromBinary : function(/*Buffer*/data) {
|
33 |
|
34 |
|
35 | if ((data.length !== Constants.ENDHDR || data.readUInt32LE(0) !== Constants.ENDSIG) &&
|
36 | (data.length < Constants.ZIP64HDR || data.readUInt32LE(0) !== Constants.ZIP64SIG)) {
|
37 |
|
38 | throw new Error(Utils.Errors.INVALID_END);
|
39 | }
|
40 |
|
41 | if (data.readUInt32LE(0) === Constants.ENDSIG) {
|
42 |
|
43 | _volumeEntries = data.readUInt16LE(Constants.ENDSUB);
|
44 |
|
45 | _totalEntries = data.readUInt16LE(Constants.ENDTOT);
|
46 |
|
47 | _size = data.readUInt32LE(Constants.ENDSIZ);
|
48 |
|
49 | _offset = data.readUInt32LE(Constants.ENDOFF);
|
50 |
|
51 | _commentLength = data.readUInt16LE(Constants.ENDCOM);
|
52 | } else {
|
53 |
|
54 | _volumeEntries = Utils.readBigUInt64LE(data, Constants.ZIP64SUB);
|
55 |
|
56 | _totalEntries = Utils.readBigUInt64LE(data, Constants.ZIP64TOT);
|
57 |
|
58 | _size = Utils.readBigUInt64LE(data, Constants.ZIP64SIZ);
|
59 |
|
60 | _offset = Utils.readBigUInt64LE(data, Constants.ZIP64OFF);
|
61 |
|
62 | _commentLength = 0;
|
63 | }
|
64 |
|
65 | },
|
66 |
|
67 | toBinary : function() {
|
68 | var b = Buffer.alloc(Constants.ENDHDR + _commentLength);
|
69 |
|
70 | b.writeUInt32LE(Constants.ENDSIG, 0);
|
71 | b.writeUInt32LE(0, 4);
|
72 |
|
73 | b.writeUInt16LE(_volumeEntries, Constants.ENDSUB);
|
74 |
|
75 | b.writeUInt16LE(_totalEntries, Constants.ENDTOT);
|
76 |
|
77 | b.writeUInt32LE(_size, Constants.ENDSIZ);
|
78 |
|
79 | b.writeUInt32LE(_offset, Constants.ENDOFF);
|
80 |
|
81 | b.writeUInt16LE(_commentLength, Constants.ENDCOM);
|
82 |
|
83 | b.fill(" ", Constants.ENDHDR);
|
84 |
|
85 | return b;
|
86 | },
|
87 |
|
88 | toString : function() {
|
89 | return '{\n' +
|
90 | '\t"diskEntries" : ' + _volumeEntries + ",\n" +
|
91 | '\t"totalEntries" : ' + _totalEntries + ",\n" +
|
92 | '\t"size" : ' + _size + " bytes,\n" +
|
93 | '\t"offset" : 0x' + _offset.toString(16).toUpperCase() + ",\n" +
|
94 | '\t"commentLength" : 0x' + _commentLength + "\n" +
|
95 | '}';
|
96 | }
|
97 | }
|
98 | }; |
\ | No newline at end of file |