Skip to content

Commit bbfd11d

Browse files
committed
more refinements.
1 parent b638c41 commit bbfd11d

5 files changed

Lines changed: 51 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You can also use `npm install https://github.com/ctalkington/node-compress-commo
1414

1515
## Things of Interest
1616

17+
- [Source Docs (coming soon)](http://docsrc.com/compress-commons/)
1718
- [Changelog](https://github.com/ctalkington/node-compress-commons/releases)
1819
- [Contributing](https://github.com/ctalkington/node-compress-commons/blob/master/CONTRIBUTING.md)
1920
- [MIT License](https://github.com/ctalkington/node-compress-commons/blob/master/LICENSE-MIT)

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,14 @@ ZipArchiveEntry.prototype.getSize = function() {
100100
return this.size;
101101
};
102102

103-
ZipArchiveEntry.prototype.getTime = function(dos) {
104-
dos = dos || false;
105-
106-
if (dos) {
107-
return this.time;
108-
}
109-
103+
ZipArchiveEntry.prototype.getTime = function() {
110104
return this.time !== -1 ? zipUtil.dosToDate(this.time) : -1;
111105
};
112106

107+
ZipArchiveEntry.prototype.getTimeDos = function() {
108+
return this.time !== -1 ? this.time : 0;
109+
};
110+
113111
ZipArchiveEntry.prototype.getUnixMode = function() {
114112
return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK);
115113
};
@@ -119,6 +117,10 @@ ZipArchiveEntry.prototype.getVersionNeededToExtract = function() {
119117
};
120118

121119
ZipArchiveEntry.prototype.setComment = function(comment) {
120+
if (Buffer.byteLength(comment) !== comment.length) {
121+
this.getGeneralPurposeBit().useUTF8ForNames(true);
122+
}
123+
122124
this.comment = comment;
123125
};
124126

@@ -167,8 +169,10 @@ ZipArchiveEntry.prototype.setMethod = function(method) {
167169
};
168170

169171
ZipArchiveEntry.prototype.setName = function(name) {
170-
if (name) {
171-
name = name.replace(/\\/g, '/').replace(/:/g, '').replace(/^\/+/, '');
172+
name = name.replace(/\\/g, '/').replace(/:/g, '').replace(/^\/+/, '');
173+
174+
if (Buffer.byteLength(name) !== name.length) {
175+
this.getGeneralPurposeBit().useUTF8ForNames(true);
172176
}
173177

174178
this.name = name;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ ZipArchiveOutputStream.prototype._finish = function() {
103103

104104
this._writeCentralDirectoryEnd();
105105

106+
this._archive.processing = false;
106107
this._archive.finish = true;
107108
this._archive.finished = true;
108109
this.end();
@@ -190,7 +191,7 @@ ZipArchiveOutputStream.prototype._writeCentralFileHeader = function(zae) {
190191
this.write(zipUtil.getShortBytes(method));
191192

192193
// datetime
193-
this.write(zipUtil.getLongBytes(zae.getTime(true)));
194+
this.write(zipUtil.getLongBytes(zae.getTimeDos()));
194195

195196
// crc32 checksum
196197
this.write(zipUtil.getLongBytes(zae.getCrc()));
@@ -267,7 +268,7 @@ ZipArchiveOutputStream.prototype._writeLocalFileHeader = function(zae) {
267268
this.write(zipUtil.getShortBytes(method));
268269

269270
// datetime
270-
this.write(zipUtil.getLongBytes(zae.getTime(true)));
271+
this.write(zipUtil.getLongBytes(zae.getTimeDos()));
271272

272273
zae._offsets.data = this.offset;
273274

test/archive-output-stream.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*global before,describe,it */
2+
var fs = require('fs');
3+
var assert = require('chai').assert;
4+
var mkdir = require('mkdirp');
5+
6+
var helpers = require('./helpers');
7+
8+
var commons = require('../lib/compress-commons');
9+
10+
var testBuffer = helpers.binaryBuffer(1024 * 16);
11+
12+
describe('ArchiveOutputStream', function() {
13+
14+
describe('#entry', function() {
15+
16+
});
17+
18+
});

test/zip-archive-entry.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ describe('ZipArchiveEntry', function() {
116116
entry.time = 1109607251;
117117
assert.typeOf(entry.getTime(), 'Date');
118118
});
119+
});
119120

120-
// add test for raw
121+
describe('#getTimeDos', function() {
122+
it('should return a number', function() {
123+
entry.time = 1109607251;
124+
assert.typeOf(entry.getTimeDos(), 'number');
125+
});
121126
});
122127

123128
describe('#getUnixMode', function() {
@@ -141,6 +146,11 @@ describe('ZipArchiveEntry', function() {
141146
entry.setComment('file comment');
142147
assert.propertyVal(entry, 'comment', 'file comment');
143148
});
149+
150+
it('should set utf8 bit when receiving strings byte count != string length', function() {
151+
entry.setComment('ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäçèéêëìíîïñòóôõöùúûüýÿ');
152+
assert.ok(entry.getGeneralPurposeBit().usesUTF8ForNames());
153+
});
144154
});
145155

146156
describe('#setCompressedSize', function() {
@@ -203,6 +213,11 @@ describe('ZipArchiveEntry', function() {
203213
entry.setName('\\windows\\file.txt');
204214
assert.propertyVal(entry, 'name', 'windows/file.txt');
205215
});
216+
217+
it('should set utf8 bit when receiving strings byte count != string length', function() {
218+
entry.setName('ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäçèéêëìíîïñòóôõöùúûüýÿ.txt');
219+
assert.ok(entry.getGeneralPurposeBit().usesUTF8ForNames());
220+
});
206221
});
207222

208223
describe('#setPlatform', function() {

0 commit comments

Comments
 (0)