node-stream-zip 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,12 @@ declare namespace StreamZip {
33
33
  * @default automatic based on file size
34
34
  */
35
35
  chunkSize?: number;
36
+
37
+ /**
38
+ * Encoding used to decode file names
39
+ * @default UTF8
40
+ */
41
+ nameEncoding?: string;
36
42
  }
37
43
 
38
44
  interface ZipEntry {
@@ -140,7 +140,8 @@ const StreamZip = function (config) {
140
140
  const ready = false,
141
141
  that = this,
142
142
  entries = config.storeEntries !== false ? {} : null,
143
- fileName = config.file;
143
+ fileName = config.file,
144
+ textDecoder = config.nameEncoding ? new TextDecoder(config.nameEncoding) : null;
144
145
 
145
146
  open();
146
147
 
@@ -343,7 +344,7 @@ const StreamZip = function (config) {
343
344
  op.move = true;
344
345
  return;
345
346
  }
346
- entry.read(buffer, bufferPos);
347
+ entry.read(buffer, bufferPos, textDecoder);
347
348
  if (!config.skipEntryNameValidation) {
348
349
  entry.validateName();
349
350
  }
@@ -877,8 +878,11 @@ class ZipEntry {
877
878
  this.extraLen = data.readUInt16LE(consts.LOCEXT);
878
879
  }
879
880
 
880
- read(data, offset) {
881
- this.name = data.slice(offset, (offset += this.fnameLen)).toString();
881
+ read(data, offset, textDecoder) {
882
+ const nameData = data.slice(offset, (offset += this.fnameLen));
883
+ this.name = textDecoder
884
+ ? textDecoder.decode(new Uint8Array(nameData))
885
+ : nameData.toString('utf8');
882
886
  const lastChar = data[offset - 1];
883
887
  this.isDirectory = lastChar === 47 || lastChar === 92;
884
888
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-stream-zip",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "node.js library for reading and extraction of ZIP archives",
5
5
  "keywords": [
6
6
  "zip",
@@ -32,7 +32,7 @@
32
32
  "url": "https://github.com/antelle/node-stream-zip.git"
33
33
  },
34
34
  "engines": {
35
- "node": ">=0.10.0"
35
+ "node": ">=0.12.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^14.14.6",