node-stream-zip 1.13.4 → 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.
package/README.md CHANGED
@@ -214,7 +214,10 @@ npm test
214
214
  ## Known issues
215
215
 
216
216
  - [utf8](https://github.com/rubyzip/rubyzip/wiki/Files-with-non-ascii-filenames) file names
217
- - AES encrypted files
217
+
218
+ ## Out of scope
219
+
220
+ - AES encrypted files: the library will throw an error if you try to open it
218
221
 
219
222
  ## Contributors
220
223
 
@@ -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 {
@@ -121,29 +127,29 @@ declare namespace StreamZip {
121
127
  */
122
128
  offset: number;
123
129
  }
124
- }
125
-
126
- type StreamZipOptions = StreamZip.StreamZipOptions;
127
- type ZipEntry = StreamZip.ZipEntry;
128
130
 
129
- declare class StreamZipAsync {
130
- constructor(config: StreamZipOptions);
131
+ class StreamZipAsync {
132
+ constructor(config: StreamZipOptions);
131
133
 
132
- entriesCount: Promise<number>;
133
- comment: Promise<string>;
134
+ entriesCount: Promise<number>;
135
+ comment: Promise<string>;
134
136
 
135
- entry(name: string): Promise<ZipEntry | undefined>;
136
- entries(): Promise<{ [name: string]: ZipEntry }>;
137
- entryData(entry: string | ZipEntry): Promise<Buffer>;
138
- stream(entry: string | ZipEntry): Promise<NodeJS.ReadableStream>;
139
- extract(entry: string | ZipEntry | null, outPath: string): Promise<number | undefined>;
137
+ entry(name: string): Promise<ZipEntry | undefined>;
138
+ entries(): Promise<{ [name: string]: ZipEntry }>;
139
+ entryData(entry: string | ZipEntry): Promise<Buffer>;
140
+ stream(entry: string | ZipEntry): Promise<NodeJS.ReadableStream>;
141
+ extract(entry: string | ZipEntry | null, outPath: string): Promise<number | undefined>;
140
142
 
141
- on(event: 'entry', handler: (entry: ZipEntry) => void): void;
142
- on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void;
143
+ on(event: 'entry', handler: (entry: ZipEntry) => void): void;
144
+ on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void;
143
145
 
144
- close(): Promise<void>;
146
+ close(): Promise<void>;
147
+ }
145
148
  }
146
149
 
150
+ type StreamZipOptions = StreamZip.StreamZipOptions;
151
+ type ZipEntry = StreamZip.ZipEntry;
152
+
147
153
  declare class StreamZip {
148
154
  constructor(config: StreamZipOptions);
149
155
 
@@ -187,7 +193,7 @@ declare class StreamZip {
187
193
 
188
194
  close(callback?: (err?: any) => void): void;
189
195
 
190
- static async: typeof StreamZipAsync;
196
+ static async: typeof StreamZip.StreamZipAsync;
191
197
  }
192
198
 
193
199
  export = StreamZip;
@@ -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
  }
@@ -533,7 +534,7 @@ const StreamZip = function (config) {
533
534
  }
534
535
  let dir = dirs.shift();
535
536
  dir = path.join(baseDir, path.join(...dir));
536
- fs.mkdir(dir, (err) => {
537
+ fs.mkdir(dir, { recursive: true }, (err) => {
537
538
  if (err && err.code !== 'EEXIST') {
538
539
  return callback(err);
539
540
  }
@@ -678,7 +679,7 @@ StreamZip.async = class StreamZipAsync extends events.EventEmitter {
678
679
 
679
680
  this[propZip] = new Promise((resolve, reject) => {
680
681
  zip.on('ready', () => {
681
- zip.off('error', reject);
682
+ zip.removeListener('error', reject);
682
683
  resolve(zip);
683
684
  });
684
685
  zip.on('error', reject);
@@ -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.13.4",
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",