Skip to content

Commit 1a334b2

Browse files
committedSep 26, 2020
add multibyte-encoded comment with byte length instead of character length
1 parent 9d2eb0b commit 1a334b2

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.4.16",
44
"description": "Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk",
55
"scripts": {
6-
"test": "mocha test/mocha.js test/crc/index.js"
6+
"test": "mocha test/mocha.js test/crc/index.js test/multibyte/test.js"
77
},
88
"keywords": [
99
"zip",

‎test/multibyte/test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { expect } = require("chai");
2+
const Utils = require("../../util");
3+
const AdmZip = require("../../adm-zip");
4+
const path = require("path");
5+
6+
describe('adm-zip', () => {
7+
it('adds multibyte ZIP comment in UTF-8 with appropriate byte', () => {
8+
const zip = new AdmZip();
9+
zip.addLocalFile(
10+
path.join(__dirname, "./じっぷ/じっぷ.txt")
11+
);
12+
zip.addZipComment("じっぷ");
13+
const willSend = zip.toBuffer();
14+
const end = willSend.slice(
15+
willSend.lastIndexOf(Utils.Constants.ENDSIG)
16+
);
17+
const commentLength = end.readInt16LE(Utils.Constants.ENDCOM, 2);
18+
expect(commentLength).to.eq(9);
19+
const expected = Buffer.from("じっぷ");
20+
const actual = end.slice(Utils.Constants.ENDCOM + 2);
21+
expect(actual).to.include(expected);
22+
expect(expected).to.include(actual);
23+
});
24+
});

‎test/multibyte/じっぷ.zip

363 Bytes
Binary file not shown.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
じっぷ

‎zipFile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ module.exports = function (/*String|Buffer*/input, /*Number*/inputType) {
133133
return _comment.toString();
134134
},
135135
set comment(val) {
136-
mainHeader.commentLength = val.length;
137-
_comment = val;
136+
_comment = Utils.toBuffer(val);
137+
mainHeader.commentLength = _comment.length;
138138
},
139139

140140
getEntryCount: function() {

0 commit comments

Comments
 (0)
Please sign in to comment.