node-stream-zip 1.14.0 → 1.16.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.
package/README.md CHANGED
@@ -195,6 +195,7 @@ zip.on('entry', entry => {
195
195
  You can pass these options to the constructor
196
196
  - `storeEntries: true` - you will be able to work with entries inside zip archive, otherwise the only way to access them is `entry` event
197
197
  - `skipEntryNameValidation: true` - by default, entry name is checked for malicious characters, like `../` or `c:\123`, pass this flag to disable validation errors
198
+ - `nameEncoding: 'utf8'` - encoding used to decode file names, UTF8 by default
198
199
 
199
200
  ## Methods
200
201
 
@@ -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
  }
@@ -863,13 +864,17 @@ class ZipEntry {
863
864
  this.crc = data.readUInt32LE(consts.LOCCRC) || this.crc;
864
865
  // compressed size
865
866
  const compressedSize = data.readUInt32LE(consts.LOCSIZ);
866
- if (compressedSize && compressedSize !== consts.EF_ZIP64_OR_32) {
867
- this.compressedSize = compressedSize;
867
+ if (
868
+ compressedSize &&
869
+ compressedSize !== consts.EF_ZIP64_OR_32 &&
870
+ compressedSize !== this.compressedSize
871
+ ) {
872
+ throw new Error('Invalid compressed size');
868
873
  }
869
874
  // uncompressed size
870
875
  const size = data.readUInt32LE(consts.LOCLEN);
871
- if (size && size !== consts.EF_ZIP64_OR_32) {
872
- this.size = size;
876
+ if (size && size !== consts.EF_ZIP64_OR_32 && size !== this.size) {
877
+ throw new Error('Invalid size');
873
878
  }
874
879
  // filename length
875
880
  this.fnameLen = data.readUInt16LE(consts.LOCNAM);
@@ -877,8 +882,11 @@ class ZipEntry {
877
882
  this.extraLen = data.readUInt16LE(consts.LOCEXT);
878
883
  }
879
884
 
880
- read(data, offset) {
881
- this.name = data.slice(offset, (offset += this.fnameLen)).toString();
885
+ read(data, offset, textDecoder) {
886
+ const nameData = data.slice(offset, (offset += this.fnameLen));
887
+ this.name = textDecoder
888
+ ? textDecoder.decode(new Uint8Array(nameData))
889
+ : nameData.toString('utf8');
882
890
  const lastChar = data[offset - 1];
883
891
  this.isDirectory = lastChar === 47 || lastChar === 92;
884
892
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-stream-zip",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "node.js library for reading and extraction of ZIP archives",
5
5
  "keywords": [
6
6
  "zip",
@@ -32,13 +32,16 @@
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
- "@types/node": "^14.14.6",
39
- "eslint": "^7.19.0",
38
+ "@eslint/js": "^10.0.1",
39
+ "@types/node": "^26.1.1",
40
+ "eslint": "^10.7.0",
41
+ "globals": "^17.7.0",
40
42
  "nodeunit": "^0.11.3",
41
- "prettier": "^2.2.1"
43
+ "prettier": "^3.9.6",
44
+ "typescript": "^7.0.2"
42
45
  },
43
46
  "funding": {
44
47
  "type": "github",