forked from archiverjs/node-compress-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip-archive-entry.js
More file actions
289 lines (236 loc) · 7.86 KB
/
Copy pathzip-archive-entry.js
File metadata and controls
289 lines (236 loc) · 7.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*global before,describe,it */
var assert = require('chai').assert;
var commons = require('../lib/compress-commons');
var ZipArchiveEntry = commons.ZipArchiveEntry;
var GeneralPurposeBit = require('../lib/archivers/zip/general-purpose-bit');
var entry;
// Jan 03 2013 14:26:38 GMT
var testDate = new Date(Date.UTC(2013, 0, 3, 14, 26, 38, 0));
describe('ZipArchiveEntry', function() {
beforeEach(function() {
entry = new ZipArchiveEntry('file.txt');
});
// Getters
describe('#getCentralDirectoryExtra', function() {
it.skip('should be tested', function() {
});
});
describe('#getComment', function() {
it('should return the comment', function() {
entry.setComment('file comment');
assert.equal(entry.getComment(), 'file comment');
});
});
describe('#getCompressedSize', function() {
it('should return the compressed size', function() {
entry.csize = 10;
assert.equal(entry.getCompressedSize(), 10);
});
});
describe('#getCrc', function() {
it('should return the CRC32', function() {
entry.crc = 585446183;
assert.equal(entry.getCrc(), 585446183);
});
});
describe('#getExternalAttributes', function() {
it('should return the external attributes', function() {
entry.exattr = 2180972576;
assert.equal(entry.getExternalAttributes(), 2180972576);
});
});
describe('#getExtra', function() {
it.skip('should be tested', function() {
});
});
describe('#getGeneralPurposeBit', function() {
it('should return the general purpose bit flag', function() {
var gpb = new GeneralPurposeBit();
gpb.useDataDescriptor(true);
entry.gpb = gpb;
assert.equal(entry.getGeneralPurposeBit(), gpb);
});
});
describe('#getInternalAttributes', function() {
it('should return the internal attributes', function() {
entry.inattr = 2180972576;
assert.equal(entry.getInternalAttributes(), 2180972576);
});
});
describe('#getLastModifiedDate', function() {
it.skip('should be tested', function() {
});
});
describe('#getLocalFileDataExtra', function() {
it.skip('should be tested', function() {
});
});
describe('#getMethod', function() {
it('should return the compression method', function() {
entry.method = 0;
assert.equal(entry.getMethod(), 0);
});
});
describe('#getName', function() {
it('should return the name', function() {
entry.name = 'file.txt';
assert.equal(entry.getName(), 'file.txt');
});
});
describe('#getPlatform', function() {
it('should return the platform', function() {
entry.platform = 3;
assert.equal(entry.getPlatform(), 3);
});
});
describe('#getSize', function() {
it('should return the size', function() {
entry.size = 25;
assert.equal(entry.getSize(), 25);
});
});
describe('#getTime', function() {
it('should return a Date object', function() {
entry.time = 1109607251;
assert.typeOf(entry.getTime(), 'Date');
});
});
describe('#getTimeDos', function() {
it('should return a number', function() {
entry.time = 1109607251;
assert.typeOf(entry.getTimeDos(), 'number');
});
});
describe('#getUnixMode', function() {
it('should return the unix filemode', function() {
entry.mode = 0777;
entry.exattr = 2180972576;
entry.platform = 3;
assert.equal(entry.getUnixMode(), 0777);
});
it('should set proper external attributes for an unix directory', function () {
entry = new ZipArchiveEntry('directory/');
entry.setUnixMode(0777);
assert.ok(entry.getPlatform(), 3);
assert.ok(entry.isDirectory());
var exattr = entry.getExternalAttributes() >> 16;
assert.equal(exattr & 040000, 040000);
});
});
describe('#getVersionNeededToExtract', function() {
it.skip('should be tested', function() {
});
});
// Setters
describe('#setComment', function() {
it('should set internal variable', function() {
entry.setComment('file comment');
assert.propertyVal(entry, 'comment', 'file comment');
});
it('should set utf8 bit when receiving strings byte count != string length', function() {
entry.setComment('ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäçèéêëìíîïñòóôõöùúûüýÿ');
assert.ok(entry.getGeneralPurposeBit().usesUTF8ForNames());
});
});
describe('#setCompressedSize', function() {
it('should set internal variable', function() {
entry.setCompressedSize(10);
assert.propertyVal(entry, 'csize', 10);
});
});
describe('#setCrc', function() {
it('should set internal variable', function() {
entry.setCrc(585446183);
assert.propertyVal(entry, 'crc', 585446183);
});
});
describe('#setExternalAttributes', function() {
it('should set internal variable', function() {
entry.setExternalAttributes(2180972576);
assert.propertyVal(entry, 'exattr', 2180972576);
});
});
describe('#setExtra', function() {
it.skip('should be tested', function() {
});
});
describe('#setGeneralPurposeBit', function() {
it('should set internal variable', function() {
var gpb = new GeneralPurposeBit();
gpb.useDataDescriptor(true);
entry.setGeneralPurposeBit(gpb);
assert.propertyVal(entry, 'gpb', gpb);
});
});
describe('#setInternalAttributes', function() {
it('should set internal variable', function() {
entry.setInternalAttributes(2180972576);
assert.propertyVal(entry, 'inattr', 2180972576);
});
});
describe('#setMethod', function() {
it('should set internal variable', function() {
entry.setMethod(8);
assert.propertyVal(entry, 'method', 8);
});
});
describe('#setName', function() {
it('should set internal variable', function() {
entry.setName('file.txt');
assert.propertyVal(entry, 'name', 'file.txt');
});
it('should allow ./ at the beginning of path', function() {
entry.setName('./file.txt');
assert.propertyVal(entry, 'name', './file.txt');
});
it('should clean windows style paths', function() {
entry.setName('\\windows\\file.txt');
assert.propertyVal(entry, 'name', 'windows/file.txt');
entry.setName('c:\\this\\path\\file.txt');
assert.propertyVal(entry, 'name', 'this/path/file.txt');
entry.setName('\\\\server\\share\\');
assert.propertyVal(entry, 'name', 'server/share/');
});
it('should set utf8 bit when receiving strings byte count != string length', function() {
entry.setName('ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäçèéêëìíîïñòóôõöùúûüýÿ.txt');
assert.ok(entry.getGeneralPurposeBit().usesUTF8ForNames());
});
});
describe('#setPlatform', function() {
it('should set internal variable', function() {
entry.setPlatform(3);
assert.propertyVal(entry, 'platform', 3);
});
});
describe('#setSize', function() {
it('should set internal variable', function() {
entry.setSize(15);
assert.propertyVal(entry, 'size', 15);
});
});
describe('#setTime', function() {
it('should set internal variable', function() {
entry.setTime(testDate);
assert.propertyVal(entry, 'time', 1109619539);
});
});
describe('#setUnixMode', function() {
it('should set internal variables', function() {
entry.setUnixMode(0777);
assert.propertyVal(entry, 'exattr', 2180972576);
assert.propertyVal(entry, 'mode', 0777);
});
});
describe('#setVersionNeededToExtract', function() {
it.skip('should be tested', function() {
});
});
// Others
describe('#isDirectory', function() {
it('should return a boolean based on name of entry', function() {
assert.notOk(entry.isDirectory());
entry.setName('some/directory/');
assert.ok(entry.isDirectory());
});
});
});