compressing 1.10.1 → 1.10.3

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.
Files changed (3) hide show
  1. package/README.md +5 -8
  2. package/lib/utils.js +33 -15
  3. package/package.json +1 -3
package/README.md CHANGED
@@ -3,6 +3,9 @@
3
3
  [![NPM version][npm-image]][npm-url]
4
4
  [![Test coverage][codecov-image]][codecov-url]
5
5
  [![npm download][download-image]][download-url]
6
+ [![Node.js Version](https://img.shields.io/node/v/compressing.svg?style=flat)](https://nodejs.org/en/download/)
7
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
8
+ ![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/node-modules/compressing)
6
9
 
7
10
  [npm-image]: https://img.shields.io/npm/v/compressing.svg?style=flat-square
8
11
  [npm-url]: https://npmjs.org/package/compressing
@@ -364,15 +367,9 @@ Due to the design of the .zip file format, it's impossible to interpret a .zip f
364
367
  Although the API is streaming style(try to keep it handy), it still loads all data into memory.
365
368
 
366
369
  <https://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api>
367
- <!-- GITCONTRIBUTOR_START -->
368
370
 
369
371
  ## Contributors
370
372
 
371
- |[<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/456108?v=4" width="100px;"/><br/><sub><b>shaoshuai0102</b></sub>](https://github.com/shaoshuai0102)<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/32174276?v=4" width="100px;"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<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/101238421?v=4" width="100px;"/><br/><sub><b>acyza</b></sub>](https://github.com/acyza)<br/>|
372
- | :---: | :---: | :---: | :---: | :---: | :---: |
373
- |[<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/20432815?v=4" width="100px;"/><br/><sub><b>rickyes</b></sub>](https://github.com/rickyes)<br/>|[<img src="https://avatars.githubusercontent.com/u/8382136?v=4" width="100px;"/><br/><sub><b>Ryqsky</b></sub>](https://github.com/Ryqsky)<br/>|[<img src="https://avatars.githubusercontent.com/u/47357585?v=4" width="100px;"/><br/><sub><b>songhn233</b></sub>](https://github.com/songhn233)<br/>|[<img src="https://avatars.githubusercontent.com/u/160386?v=4" width="100px;"/><br/><sub><b>Infiltrator</b></sub>](https://github.com/Infiltrator)<br/>|[<img src="https://avatars.githubusercontent.com/u/13861843?v=4" width="100px;"/><br/><sub><b>ZeekoZhu</b></sub>](https://github.com/ZeekoZhu)<br/>|
374
- [<img src="https://avatars.githubusercontent.com/u/6897780?v=4" width="100px;"/><br/><sub><b>killagu</b></sub>](https://github.com/killagu)<br/>|[<img src="https://avatars.githubusercontent.com/u/59508678?v=4" width="100px;"/><br/><sub><b>okaponta</b></sub>](https://github.com/okaponta)<br/>|[<img src="https://avatars.githubusercontent.com/u/9857273?v=4" width="100px;"/><br/><sub><b>ShadyZOZ</b></sub>](https://github.com/ShadyZOZ)<br/>
373
+ [![Contributors](https://contrib.rocks/image?repo=node-modules/compressing)](https://github.com/node-modules/compressing/graphs/contributors)
375
374
 
376
- This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Thu Aug 03 2023 01:39:37 GMT+0800`.
377
-
378
- <!-- GITCONTRIBUTOR_END -->
375
+ Made with [contributors-img](https://contrib.rocks).
package/lib/utils.js CHANGED
@@ -109,31 +109,37 @@ exports.makeUncompressFn = StreamClass => {
109
109
  .on('error', reject)
110
110
  .on('entry', (header, stream, next) => {
111
111
  stream.on('end', next);
112
+ const destFilePath = path.join(destDir, header.name);
112
113
 
113
114
  if (header.type === 'file') {
114
- const fullpath = path.join(destDir, header.name);
115
- mkdirp(path.dirname(fullpath), err => {
115
+ const dir = path.dirname(destFilePath);
116
+ mkdirp(dir, err => {
116
117
  if (err) return reject(err);
117
118
 
118
119
  entryCount++;
119
- pump(stream, fs.createWriteStream(fullpath, { mode: opts.mode || header.mode }), err => {
120
+ pump(stream, fs.createWriteStream(destFilePath, { mode: opts.mode || header.mode }), err => {
120
121
  if (err) return reject(err);
121
122
  successCount++;
122
123
  done();
123
124
  });
124
125
  });
125
126
  } else if (header.type === 'symlink') {
126
- // symlink
127
- const src = path.join(destDir, header.name);
128
- const target = path.resolve(path.dirname(src), header.linkname);
127
+ const dir = path.dirname(destFilePath);
128
+ const target = path.resolve(dir, header.linkname);
129
129
  entryCount++;
130
- fs.symlink(target, src, err => {
130
+
131
+ mkdirp(dir, err => {
131
132
  if (err) return reject(err);
132
- successCount++;
133
- stream.resume();
133
+
134
+ const relativeTarget = path.relative(dir, target);
135
+ fs.symlink(relativeTarget, destFilePath, err => {
136
+ if (err) return reject(err);
137
+ successCount++;
138
+ stream.resume();
139
+ });
134
140
  });
135
141
  } else { // directory
136
- mkdirp(path.join(destDir, header.name), err => {
142
+ mkdirp(destFilePath, err => {
137
143
  if (err) return reject(err);
138
144
  stream.resume();
139
145
  });
@@ -168,7 +174,14 @@ function safePipe(streams) {
168
174
 
169
175
  exports.safePipe = safePipe;
170
176
 
171
- exports.stripFileName = (strip, fileName, type) => {
177
+ function normalizePath(fileName) {
178
+ fileName = path.normalize(fileName);
179
+ // https://nodejs.org/api/path.html#path_path_normalize_path
180
+ if (process.platform === 'win32') fileName = fileName.replace(/\\+/g, '/');
181
+ return fileName;
182
+ }
183
+
184
+ function stripFileName(strip, fileName, type) {
172
185
  // before
173
186
  // node/package.json
174
187
  // node/lib/index.js
@@ -189,15 +202,18 @@ exports.stripFileName = (strip, fileName, type) => {
189
202
  // /foo => foo
190
203
  if (fileName[0] === '/') fileName = fileName.replace(/^\/+/, '');
191
204
 
205
+ // fix case
206
+ // ./foo/bar => foo/bar
207
+ if (fileName) {
208
+ fileName = normalizePath(fileName);
209
+ }
210
+
192
211
  let s = fileName.split('/');
193
212
 
194
213
  // fix relative path
195
214
  // foo/../bar/../../asdf/
196
215
  // => asdf/
197
216
  if (s.indexOf('..') !== -1) {
198
- fileName = path.normalize(fileName);
199
- // https://npm.taobao.org/mirrors/node/latest/docs/api/path.html#path_path_normalize_path
200
- if (process.platform === 'win32') fileName = fileName.replace(/\\+/g, '/');
201
217
  // replace '../' on ../../foo/bar
202
218
  fileName = fileName.replace(/(\.\.\/)+/, '');
203
219
  if (type === 'directory' && fileName && fileName[fileName.length - 1] !== '/') {
@@ -208,4 +224,6 @@ exports.stripFileName = (strip, fileName, type) => {
208
224
 
209
225
  strip = Math.min(strip, s.length - 1);
210
226
  return s.slice(strip).join('/') || '/';
211
- };
227
+ }
228
+
229
+ exports.stripFileName = stripFileName;
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "compressing",
3
- "version": "1.10.1",
3
+ "version": "1.10.3",
4
4
  "description": "Everything you need for compressing and uncompressing",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "contributor": "git-contributor",
8
7
  "test:ts": "tsc -p ./test/fixtures/types/tsconfig.json",
9
8
  "test:js": "egg-bin test --ts false",
10
9
  "test": "npm run test:js && npm run test:ts",
@@ -57,7 +56,6 @@
57
56
  "egg-bin": "6",
58
57
  "eslint": "8",
59
58
  "eslint-config-egg": "12",
60
- "git-contributor": "2",
61
59
  "mm": "^2.0.0",
62
60
  "mz-modules": "^2.1.0",
63
61
  "typescript": "5",