Skip to content

Commit dd0d369

Browse files
committed
Extract toUtf8
1 parent fc0f18b commit dd0d369

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
LiteJS Zip – [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6]
1111
==========
1212

13-
Lightweight (~1.2KB) ZIP file creator for Browser and Node.js. No dependencies.
13+
Lightweight (~1.3KB) ZIP file creator for Browser and Node.js. No dependencies.
1414
Uses the CompressionStream API when available; otherwise will generate uncompressed ZIP.
1515

1616

zip.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* globals Blob, Promise, Response */
44

5-
;((exports, unescape, encodeURIComponent, Uint8Array) => {
5+
;((exports, Uint8Array) => {
66

77
// Attach createZip to `window` in non-module context
88
exports.createZip = (files, opts, next) => {
@@ -28,6 +28,7 @@
2828
for (var pos = str.length, arr = new Uint8Array(pos); pos--; arr[pos] = str.charCodeAt(pos));
2929
return arr
3030
}
31+
, toUtf8 = str => unescape(encodeURIComponent(str || ""))
3132
, compress = (uint, len, cb) => {
3233
if (opts && opts.deflate) {
3334
var compressed = opts.deflate(uint)
@@ -44,19 +45,19 @@
4445
k = files[i++]
4546
if (!k) {
4647
k = files.length
47-
name = unescape(encodeURIComponent(opts && opts.comment || ""))
48+
name = toUtf8(opts && opts.comment)
4849
push(toUint(cd + "PK\5\6" + le32(0) + le32((k<<16) + k) + le32(cd.length) + le32(offset) + le16(name.length) + name))
4950
file = new Uint8Array(outLen)
5051
for (i = 0, offset = 0; (j = out[i++]); offset += j.length) file.set(j, offset);
5152
return resolve(file)
5253
}
5354
var fileLen
54-
, name = unescape(encodeURIComponent(k.name))
55+
, name = toUtf8(k.name)
5556
, nameLen = name.length
5657
, file = k.content
5758
, crc = -1
5859

59-
if (typeof file === "string") file = toUint(unescape(encodeURIComponent(file)))
60+
if (typeof file === "string") file = toUint(toUtf8(file))
6061
fileLen = file.length
6162

6263
for (j = 0; j < fileLen; ) {
@@ -83,5 +84,5 @@
8384
}
8485

8586
// this is `exports` in module and `window` in browser
86-
})(this, unescape, encodeURIComponent, Uint8Array) // jshint ignore:line
87+
})(this, Uint8Array) // jshint ignore:line
8788

0 commit comments

Comments
 (0)