Skip to content

Commit 957376b

Browse files
committed
feat: support strip for all archive
1 parent b2d231b commit 957376b

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

lib/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ exports.makeUncompressFn = StreamClass => {
8888
throw error;
8989
}
9090

91+
const strip = opts.strip ? Number(opts.strip) : 0;
92+
9193
return new Promise((resolve, reject) => {
9294
fs.mkdir(destDir, { recursive: true }, err => {
9395
if (err) return reject(err);
@@ -108,8 +110,7 @@ exports.makeUncompressFn = StreamClass => {
108110
.on('error', reject)
109111
.on('entry', (header, stream, next) => {
110112
stream.on('end', next);
111-
const destFilePath = path.join(destDir, header.name);
112-
113+
const destFilePath = path.join(destDir, stripFileName(strip, header.name, header.type));
113114
if (header.type === 'file') {
114115
const dir = path.dirname(destFilePath);
115116
fs.mkdir(dir, { recursive: true }, err => {

lib/zip/uncompress_stream.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const utils = require('../utils');
1212
let iconv;
1313

1414
const YAUZL_CALLBACK = Symbol('ZipUncompressStream#yauzlCallback');
15-
const STRIP_NAME = Symbol('ZipUncompressStream#stripName');
1615

1716
// don't decodeStrings on yauzl, we should handle fileName by ourself
1817
// see validateFileName on https://github.com/thejoshwolfe/yauzl/blob/51010ce4e8c7e6345efe195e1b4150518f37b393/index.js#L607
@@ -34,7 +33,6 @@ class ZipUncompressStream extends UncompressBaseStream {
3433
super(opts);
3534

3635
this._chunks = [];
37-
this._strip = Number(opts.strip) || 0;
3836
this._zipFileNameEncoding = opts.zipFileNameEncoding || 'utf8';
3937
if (this._zipFileNameEncoding === 'utf-8') {
4038
this._zipFileNameEncoding = 'utf8';
@@ -108,7 +106,7 @@ class ZipUncompressStream extends UncompressBaseStream {
108106
}
109107
// directory file names end with '/' (for Linux and macOS) or '\' (for Windows)
110108
const type = /[\\\/]$/.test(entry.fileName) ? 'directory' : 'file';
111-
const name = entry.fileName = this[STRIP_NAME](entry.fileName, type);
109+
const name = entry.fileName;
112110

113111
const header = { name, type, yauzl: entry, mode };
114112

@@ -135,10 +133,6 @@ class ZipUncompressStream extends UncompressBaseStream {
135133
zipFile.readEntry();
136134
}
137135
}
138-
139-
[STRIP_NAME](fileName, type) {
140-
return utils.stripFileName(this._strip, fileName, type);
141-
}
142136
}
143137

144138
module.exports = ZipUncompressStream;

0 commit comments

Comments
 (0)