compressing 1.10.0 → 1.10.2
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/lib/utils.js +13 -3
- package/lib/zip/uncompress_stream.js +2 -2
- package/package.json +5 -4
package/lib/utils.js
CHANGED
|
@@ -168,6 +168,13 @@ function safePipe(streams) {
|
|
|
168
168
|
|
|
169
169
|
exports.safePipe = safePipe;
|
|
170
170
|
|
|
171
|
+
function normalizePath(fileName) {
|
|
172
|
+
fileName = path.normalize(fileName);
|
|
173
|
+
// https://nodejs.org/api/path.html#path_path_normalize_path
|
|
174
|
+
if (process.platform === 'win32') fileName = fileName.replace(/\\+/g, '/');
|
|
175
|
+
return fileName;
|
|
176
|
+
}
|
|
177
|
+
|
|
171
178
|
exports.stripFileName = (strip, fileName, type) => {
|
|
172
179
|
// before
|
|
173
180
|
// node/package.json
|
|
@@ -189,15 +196,18 @@ exports.stripFileName = (strip, fileName, type) => {
|
|
|
189
196
|
// /foo => foo
|
|
190
197
|
if (fileName[0] === '/') fileName = fileName.replace(/^\/+/, '');
|
|
191
198
|
|
|
199
|
+
// fix case
|
|
200
|
+
// ./foo/bar => foo/bar
|
|
201
|
+
if (fileName) {
|
|
202
|
+
fileName = normalizePath(fileName);
|
|
203
|
+
}
|
|
204
|
+
|
|
192
205
|
let s = fileName.split('/');
|
|
193
206
|
|
|
194
207
|
// fix relative path
|
|
195
208
|
// foo/../bar/../../asdf/
|
|
196
209
|
// => asdf/
|
|
197
210
|
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
211
|
// replace '../' on ../../foo/bar
|
|
202
212
|
fileName = fileName.replace(/(\.\.\/)+/, '');
|
|
203
213
|
if (type === 'directory' && fileName && fileName[fileName.length - 1] !== '/') {
|
|
@@ -98,8 +98,8 @@ class ZipUncompressStream extends UncompressBaseStream {
|
|
|
98
98
|
entry.fileName = iconv.decode(entry.fileName, this._zipFileNameEncoding);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
// directory file names end with '/'
|
|
102
|
-
const type =
|
|
101
|
+
// directory file names end with '/' (for Linux and macOS) or '\' (for Windows)
|
|
102
|
+
const type = /[\\\/]$/.test(entry.fileName) ? 'directory' : 'file';
|
|
103
103
|
const name = entry.fileName = this[STRIP_NAME](entry.fileName, type);
|
|
104
104
|
|
|
105
105
|
const header = { name, type, yauzl: entry, mode };
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compressing",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "Everything you need for compressing and uncompressing",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"contributor": "git-contributor",
|
|
8
|
-
"ts
|
|
9
|
-
"test": "egg-bin test --ts false
|
|
8
|
+
"test:ts": "tsc -p ./test/fixtures/types/tsconfig.json",
|
|
9
|
+
"test:js": "egg-bin test --ts false",
|
|
10
|
+
"test": "npm run test:js && npm run test:ts",
|
|
10
11
|
"cov": "egg-bin cov --ts false",
|
|
11
12
|
"lint-fix": "eslint . --fix",
|
|
12
13
|
"lint": "eslint .",
|
|
13
|
-
"ci": "npm run lint && npm run ts
|
|
14
|
+
"ci": "npm run lint && npm run test:ts && npm run cov"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|