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.
- package/README.md +5 -8
- package/lib/utils.js +33 -15
- 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
|
+
[](https://nodejs.org/en/download/)
|
|
7
|
+
[](https://makeapullrequest.com)
|
|
8
|
+

|
|
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
|
-
|
|
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
|
+
[](https://github.com/node-modules/compressing/graphs/contributors)
|
|
375
374
|
|
|
376
|
-
|
|
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
|
|
115
|
-
mkdirp(
|
|
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(
|
|
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
|
-
|
|
127
|
-
const
|
|
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
|
-
|
|
130
|
+
|
|
131
|
+
mkdirp(dir, err => {
|
|
131
132
|
if (err) return reject(err);
|
|
132
|
-
|
|
133
|
-
|
|
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(
|
|
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
|
-
|
|
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.
|
|
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",
|