compressing 1.4.0 → 1.6.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/History.md CHANGED
@@ -1,4 +1,31 @@
1
1
 
2
+ 1.6.0 / 2022-06-13
3
+ ==================
4
+
5
+ **features**
6
+ * [[`bd8ef44`](http://github.com/node-modules/compressing/commit/bd8ef44ade2f4b93d41ff2f78d6f17902d965798)] - feat: unzip should keep file mode (#68) (Artin <<lengthmin@gmail.com>>)
7
+
8
+ **others**
9
+ * [[`592e518`](http://github.com/node-modules/compressing/commit/592e5180dfbdbc6cb1becd1baf6a007ce7b7cd39)] - Create codeql-analysis.yml (fengmk2 <<fengmk2@gmail.com>>)
10
+
11
+ 1.5.1 / 2020-05-11
12
+ ==================
13
+
14
+ **fixes**
15
+ * [[`f516814`](http://github.com/node-modules/compressing/commit/f51681490aeea44a7b27ec0c09d3fb3d0385c5c0)] - fix: index.d.ts streamHeader.name wrong declearing (#46) (shadyzoz <<ShadyZOZ@users.noreply.github.com>>)
16
+
17
+ 1.5.0 / 2019-12-04
18
+ ==================
19
+
20
+ **features**
21
+ * [[`15c29e9`](http://github.com/node-modules/compressing/commit/15c29e9893880d2c19c343d133edb50f0c55c713)] - feat: zip format support custom fileName encoding (#36) (fengmk2 <<fengmk2@gmail.com>>)
22
+
23
+ **fixes**
24
+ * [[`7d605fe`](http://github.com/node-modules/compressing/commit/7d605fe01a88bc6aab9a2b06a8725545f591bab9)] - fix: typescript error(#29) (Ruanyq <<yiqiang0930@163.com>>)
25
+
26
+ **others**
27
+ * [[`4808fb8`](http://github.com/node-modules/compressing/commit/4808fb8e1d6cbbb31c0e82c359ec04eccb0c1eaf)] - test: add node 11 (#20) (fengmk2 <<fengmk2@gmail.com>>)
28
+
2
29
  1.4.0 / 2018-11-30
3
30
  ==================
4
31
 
package/README.md CHANGED
@@ -1,22 +1,13 @@
1
1
  # compressing
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
- [![build status][travis-image]][travis-url]
5
4
  [![Test coverage][codecov-image]][codecov-url]
6
- [![David deps][david-image]][david-url]
7
- [![Known Vulnerabilities][snyk-image]][snyk-url]
8
5
  [![npm download][download-image]][download-url]
9
6
 
10
7
  [npm-image]: https://img.shields.io/npm/v/compressing.svg?style=flat-square
11
8
  [npm-url]: https://npmjs.org/package/compressing
12
- [travis-image]: https://img.shields.io/travis/node-modules/compressing.svg?style=flat-square
13
- [travis-url]: https://travis-ci.org/node-modules/compressing
14
9
  [codecov-image]: https://codecov.io/gh/node-modules/compressing/branch/master/graph/badge.svg
15
10
  [codecov-url]: https://codecov.io/gh/node-modules/compressing
16
- [david-image]: https://img.shields.io/david/node-modules/compressing.svg?style=flat-square
17
- [david-url]: https://david-dm.org/node-modules/compressing
18
- [snyk-image]: https://snyk.io/test/npm/compressing/badge.svg?style=flat-square
19
- [snyk-url]: https://snyk.io/test/npm/compressing
20
11
  [download-image]: https://img.shields.io/npm/dm/compressing.svg?style=flat-square
21
12
  [download-url]: https://npmjs.org/package/compressing
22
13
 
@@ -88,7 +79,6 @@ const destStream = fs.createWriteStream('path/to/destination.gz');
88
79
  pump(sourceStream, gzipStream, destStream, handleError);
89
80
  ```
90
81
 
91
-
92
82
  ### Compress a dir
93
83
 
94
84
  Use tar as an example, tgz and zip is same as gzip.
@@ -167,8 +157,7 @@ compressing.tgz.uncompress(stream, 'path/to/destination/dir')
167
157
  .catch(handleError);
168
158
  ```
169
159
 
170
- **Note: tar, tgz and zip have the same uncompressing API as above: destination should be a path of a directory, while that of gzip is slightly different: destination must be a file or filestream.**
171
-
160
+ __Note: tar, tgz and zip have the same uncompressing API as above: destination should be a path of a directory, while that of gzip is slightly different: destination must be a file or filestream.__
172
161
 
173
162
  And working with urllib is super easy. Let's download a tgz file and uncompress to a directory:
174
163
 
@@ -280,8 +269,14 @@ Use this API to uncompress a file. This is a convenient method, which wraps Unco
280
269
  Params
281
270
 
282
271
  - source {String|Buffer|Stream} - source to be uncompressed
283
- - dest {String|Stream} - uncompressing destination. When uncompressing tar, tgz and zip, it should be a directory path (eg. `/path/to/xx`). **When uncompressing gzip, it should be a file path or a writable stream.**
272
+ - dest {String|Stream} - uncompressing destination. When uncompressing tar, tgz and zip, it should be a directory path (eg. `/path/to/xx`). __When uncompressing gzip, it should be a file path or a writable stream.__
284
273
  - opts {Object} - usually you don't need it
274
+ - opts.zipFileNameEncoding {String} - Only work on zip format, default is 'utf8'.
275
+ Major non-UTF8 encodings by languages:
276
+
277
+ - Korean: cp949, euc-kr
278
+ - Japanese: sjis (shift_jis), cp932, euc-jp
279
+ - Chinese: gbk, gb18030, gb2312, cp936, hkscs, big5, cp950
285
280
 
286
281
  ### FileStream
287
282
 
@@ -368,7 +363,15 @@ Due to the design of the .zip file format, it's impossible to interpret a .zip f
368
363
 
369
364
  Although the API is streaming style(try to keep it handy), it still loads all data into memory.
370
365
 
371
- https://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api
366
+ <https://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api>
367
+ <!-- GITCONTRIBUTOR_START -->
368
+
369
+ ## Contributors
372
370
 
371
+ |[<img src="https://avatars.githubusercontent.com/u/456108?v=4" width="100px;"/><br/><sub><b>shaoshuai0102</b></sub>](https://github.com/shaoshuai0102)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars.githubusercontent.com/u/9692408?v=4" width="100px;"/><br/><sub><b>DiamondYuan</b></sub>](https://github.com/DiamondYuan)<br/>|[<img src="https://avatars.githubusercontent.com/u/13938334?v=4" width="100px;"/><br/><sub><b>bytemain</b></sub>](https://github.com/bytemain)<br/>|[<img src="https://avatars.githubusercontent.com/u/8382136?v=4" width="100px;"/><br/><sub><b>Ryqsky</b></sub>](https://github.com/Ryqsky)<br/>|
372
+ | :---: | :---: | :---: | :---: | :---: | :---: |
373
+ [<img src="https://avatars.githubusercontent.com/u/9857273?v=4" width="100px;"/><br/><sub><b>ShadyZOZ</b></sub>](https://github.com/ShadyZOZ)<br/>
373
374
 
375
+ This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Jun 13 2022 13:26:08 GMT+0800`.
374
376
 
377
+ <!-- GITCONTRIBUTOR_END -->
package/index.d.ts CHANGED
@@ -1,23 +1,33 @@
1
- import {ReadStream, WriteStream} from 'fs'
1
+ import { ReadStream, WriteStream } from 'fs'
2
2
 
3
- type sourceType = string | Buffer | ReadStream;
3
+ type sourceType = string | Buffer | ReadStream
4
4
 
5
- type destType = string | WriteStream;
5
+ type destType = string | WriteStream
6
6
 
7
- type streamEntryOpts = {
8
- relativePath?: string;
9
- ignoreBase?: boolean;
10
- size?: number;
7
+ interface streamEntryOpts {
8
+ relativePath?: string
9
+ ignoreBase?: boolean
10
+ size?: number
11
11
  }
12
12
 
13
+ interface streamHeader {
14
+ type: 'file' | 'directory',
15
+ name: string
16
+ }
17
+
18
+ interface streamHeaderWithMode {
19
+ type: 'file' | 'directory',
20
+ name: string
21
+ mode: number
22
+ }
13
23
 
14
24
  export namespace gzip {
15
25
 
16
- function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>;
26
+ function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
17
27
 
18
- function uncompress(source: sourceType, dest: destType, opts?: any): Promise<void>;
28
+ function uncompress(source: sourceType, dest: destType, opts?: any): Promise<void>
19
29
 
20
- export class FileStream {
30
+ export class FileStream extends ReadStream {
21
31
 
22
32
  constructor(opts?: {
23
33
  zlib?: object,
@@ -26,14 +36,15 @@ export namespace gzip {
26
36
 
27
37
  }
28
38
 
29
- export class UncompressStream {
39
+ export class UncompressStream extends WriteStream {
30
40
 
31
41
  constructor(opts?: {
32
42
  zlib?: object,
33
43
  source: sourceType
34
44
  });
35
45
 
36
- on(event: 'error', cb: Function)
46
+ on(event: string, listener: (...args: any[]) => void): this
47
+ on(event: 'error', listener: (err: Error) => void): this
37
48
 
38
49
  }
39
50
 
@@ -41,22 +52,22 @@ export namespace gzip {
41
52
 
42
53
  export namespace tar {
43
54
 
44
- function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>;
55
+ function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
45
56
 
46
- function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>;
57
+ function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>
47
58
 
48
- function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>;
59
+ function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>
49
60
 
50
- export class Stream {
61
+ export class Stream extends ReadStream {
51
62
 
52
63
  constructor();
53
64
 
54
- addEntry(entry: string, opts?: streamEntryOpts);
65
+ addEntry(entry: string, opts?: streamEntryOpts): void
55
66
 
56
- addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts);
67
+ addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void
57
68
  }
58
69
 
59
- export class FileStream {
70
+ export class FileStream extends ReadStream {
60
71
 
61
72
  constructor(opts?: {
62
73
  relativePath?: string,
@@ -67,14 +78,16 @@ export namespace tar {
67
78
 
68
79
  }
69
80
 
70
- export class UncompressStream {
81
+ export class UncompressStream extends WriteStream {
71
82
 
72
83
  constructor(opts?: {
73
84
  source: sourceType
74
85
  });
75
86
 
76
-
77
- on(event: 'error', cb: Function)
87
+ on(event: string, listener: (...args: any[]) => void): this
88
+ on(event: 'entry', listener: (header: streamHeaderWithMode, stream: WriteStream, next: () => void) => void): this
89
+ on(event: 'finish', listener: () => void): this
90
+ on(event: 'error', listener: (err: Error) => void): this
78
91
 
79
92
  }
80
93
 
@@ -82,22 +95,22 @@ export namespace tar {
82
95
 
83
96
  export namespace tgz {
84
97
 
85
- function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>;
98
+ function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
86
99
 
87
- function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>;
100
+ function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>
88
101
 
89
- function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>;
102
+ function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>
90
103
 
91
- export class Stream {
104
+ export class Stream extends ReadStream {
92
105
 
93
106
  constructor();
94
107
 
95
- addEntry(entry: string, opts?: streamEntryOpts);
108
+ addEntry(entry: string, opts?: streamEntryOpts): void
96
109
 
97
- addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts);
110
+ addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void
98
111
  }
99
112
 
100
- export class FileStream {
113
+ export class FileStream extends ReadStream {
101
114
 
102
115
  constructor(opts?: {
103
116
  relativePath?: string,
@@ -109,14 +122,17 @@ export namespace tgz {
109
122
 
110
123
  }
111
124
 
112
- export class UncompressStream {
125
+ export class UncompressStream extends WriteStream {
113
126
 
114
127
  constructor(opts?: {
115
128
  source?: sourceType,
116
129
  strip?: number
117
130
  });
118
131
 
119
- on(event: 'entry' | 'finish' | 'error', cb: Function)
132
+ on(event: string, listener: (...args: any[]) => void): this
133
+ on(event: 'entry', listener: (header: streamHeaderWithMode, stream: WriteStream, next: () => void) => void): this
134
+ on(event: 'finish', listener: () => void): this
135
+ on(event: 'error', listener: (err: Error) => void): this
120
136
 
121
137
  }
122
138
 
@@ -124,22 +140,22 @@ export namespace tgz {
124
140
 
125
141
  export namespace zip {
126
142
 
127
- function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>;
143
+ function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
128
144
 
129
- function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>;
145
+ function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>
130
146
 
131
- function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>;
147
+ function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>
132
148
 
133
- export class Stream {
149
+ export class Stream extends ReadStream {
134
150
 
135
151
  constructor();
136
152
 
137
- addEntry(entry: string, opts?: streamEntryOpts);
153
+ addEntry(entry: string, opts?: streamEntryOpts): void
138
154
 
139
- addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts);
155
+ addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void
140
156
  }
141
157
 
142
- export class FileStream {
158
+ export class FileStream extends ReadStream {
143
159
 
144
160
  /**
145
161
  * If opts.source is a file path, opts.relativePath is optional, otherwise it's required.
@@ -148,26 +164,29 @@ export namespace zip {
148
164
  */
149
165
  constructor(opts?: {
150
166
  relativePath?: string,
151
- yazl?: Object,
167
+ yazl?: object,
152
168
  source: string
153
169
  } | {
154
170
  relativePath: string,
155
- yazl?: Object,
171
+ yazl?: object,
156
172
  source?: Buffer | ReadStream
157
173
  });
158
174
 
159
175
  }
160
176
 
161
- export class UncompressStream {
177
+ export class UncompressStream extends WriteStream {
162
178
 
163
179
  constructor(opts?: {
164
180
  source?: sourceType,
165
- strip?: number
181
+ strip?: number,
182
+ zipFileNameEncoding?: string
166
183
  });
167
184
 
168
- on(event: 'entry' | 'finish' | 'error', cb: Function)
185
+ on(event: string, listener: (...args: any[]) => void): this
186
+ on(event: 'entry', listener: (header: streamHeaderWithMode, stream: WriteStream, next: () => void) => void): this
187
+ on(event: 'finish', listener: () => void): this
188
+ on(event: 'error', listener: (err: Error) => void): this
169
189
 
170
190
  }
171
191
 
172
192
  }
173
-
@@ -7,6 +7,9 @@ const stream = require('stream');
7
7
  const UncompressBaseStream = require('../base_write_stream');
8
8
  const utils = require('../utils');
9
9
 
10
+ // lazy load iconv-lite
11
+ let iconv;
12
+
10
13
  const YAUZL_CALLBACK = Symbol('ZipUncompressStream#yauzlCallback');
11
14
  const STRIP_NAME = Symbol('ZipUncompressStream#stripName');
12
15
 
@@ -15,6 +18,15 @@ const STRIP_NAME = Symbol('ZipUncompressStream#stripName');
15
18
  // - support "absolute path"
16
19
  const DEFAULTS = { lazyEntries: true, decodeStrings: false };
17
20
 
21
+ // from: https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/node/zip.ts#L51
22
+ function modeFromEntry(entry) {
23
+ const attr = entry.externalFileAttributes >> 16 || 33188;
24
+
25
+ return [ 448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */ ]
26
+ .map(mask => attr & mask)
27
+ .reduce((a, b) => a + b, attr & 61440 /* S_IFMT */);
28
+ }
29
+
18
30
  class ZipUncompressStream extends UncompressBaseStream {
19
31
  constructor(opts) {
20
32
  opts = opts || {};
@@ -22,6 +34,10 @@ class ZipUncompressStream extends UncompressBaseStream {
22
34
 
23
35
  this._chunks = [];
24
36
  this._strip = Number(opts.strip) || 0;
37
+ this._zipFileNameEncoding = opts.zipFileNameEncoding || 'utf8';
38
+ if (this._zipFileNameEncoding === 'utf-8') {
39
+ this._zipFileNameEncoding = 'utf8';
40
+ }
25
41
 
26
42
  this[YAUZL_CALLBACK] = this[YAUZL_CALLBACK].bind(this);
27
43
 
@@ -70,11 +86,23 @@ class ZipUncompressStream extends UncompressBaseStream {
70
86
 
71
87
  zipFile
72
88
  .on('entry', entry => {
89
+ const mode = modeFromEntry(entry);
90
+ // fileName is buffer by default because decodeStrings = false
91
+ if (Buffer.isBuffer(entry.fileName)) {
92
+ if (this._zipFileNameEncoding === 'utf8') {
93
+ entry.fileName = entry.fileName.toString();
94
+ } else {
95
+ if (!iconv) {
96
+ iconv = require('iconv-lite');
97
+ }
98
+ entry.fileName = iconv.decode(entry.fileName, this._zipFileNameEncoding);
99
+ }
100
+ }
73
101
  // directory file names end with '/'
74
102
  const type = /\/$/.test(entry.fileName) ? 'directory' : 'file';
75
103
  const name = entry.fileName = this[STRIP_NAME](entry.fileName, type);
76
104
 
77
- const header = { name, type, yauzl: entry };
105
+ const header = { name, type, yauzl: entry, mode };
78
106
 
79
107
  if (type === 'file') {
80
108
  zipFile.openReadStream(entry, (err, readStream) => {
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "compressing",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Everything you need for compressing and uncompressing",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "egg-bin test && tsc -p ./test/fixtures/types/tsconfig.json",
7
+ "contributor": "git-contributor",
8
+ "ts-test": "tsc -p ./test/fixtures/types/tsconfig.json",
9
+ "test": "egg-bin test && npm run ts-test",
8
10
  "cov": "egg-bin cov",
9
11
  "lint": "eslint .",
10
- "ci": "npm run lint && npm run cov"
12
+ "ci": "npm run lint && npm run ts-test && npm run cov"
11
13
  },
12
14
  "repository": {
13
15
  "type": "git",
@@ -38,6 +40,7 @@
38
40
  "dependencies": {
39
41
  "flushwritable": "^1.0.0",
40
42
  "get-ready": "^1.0.0",
43
+ "iconv-lite": "^0.5.0",
41
44
  "mkdirp": "^0.5.1",
42
45
  "pump": "^3.0.0",
43
46
  "streamifier": "^0.1.1",
@@ -53,6 +56,7 @@
53
56
  "egg-ci": "^1.8.0",
54
57
  "eslint": "^3.10.2",
55
58
  "eslint-config-egg": "^3.2.0",
59
+ "git-contributor": "^1.1.0",
56
60
  "mm": "^2.0.0",
57
61
  "mz-modules": "^2.1.0",
58
62
  "power-assert": "^1.4.2",
@@ -64,7 +68,7 @@
64
68
  "node": ">= 4.0.0"
65
69
  },
66
70
  "ci": {
67
- "version": "4, 6, 8, 10",
71
+ "version": "4, 6, 8, 10, 12",
68
72
  "license": {
69
73
  "year": "2017",
70
74
  "fullname": "node-modules and other contributors"