compressing 2.0.1 → 2.1.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/README.md +2 -0
- package/lib/utils.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -280,6 +280,7 @@ Params
|
|
|
280
280
|
- Korean: cp949, euc-kr
|
|
281
281
|
- Japanese: sjis (shift_jis), cp932, euc-jp
|
|
282
282
|
- Chinese: gbk, gb18030, gb2312, cp936, hkscs, big5, cp950
|
|
283
|
+
- opts.strip {Number} - Strip leading path segments when extracting (tar/tgz/zip). Default is 0.
|
|
283
284
|
|
|
284
285
|
### FileStream
|
|
285
286
|
|
|
@@ -359,6 +360,7 @@ __Constructor__
|
|
|
359
360
|
Common params:
|
|
360
361
|
|
|
361
362
|
- opts.source {String|Buffer|Stream} - source to be uncompressed, could be a file path, buffer, or a readable stream.
|
|
363
|
+
- opts.strip {Number} - Strip leading path segments when extracting (tar/tgz/zip). Default is 0.
|
|
362
364
|
|
|
363
365
|
__CAUTION for zip.UncompressStream__
|
|
364
366
|
|
package/lib/utils.js
CHANGED
|
@@ -104,6 +104,10 @@ exports.makeUncompressFn = StreamClass => {
|
|
|
104
104
|
throw error;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
const strip = opts.strip ? Number(opts.strip) : 0;
|
|
108
|
+
// Strip is handled here in makeUncompressFn, so remove it from opts to avoid passing to UncompressStream
|
|
109
|
+
delete opts.strip;
|
|
110
|
+
|
|
107
111
|
return new Promise((resolve, reject) => {
|
|
108
112
|
fs.mkdir(destDir, { recursive: true }, err => {
|
|
109
113
|
if (err) return reject(err);
|
|
@@ -127,7 +131,7 @@ exports.makeUncompressFn = StreamClass => {
|
|
|
127
131
|
.on('error', reject)
|
|
128
132
|
.on('entry', (header, stream, next) => {
|
|
129
133
|
stream.on('end', next);
|
|
130
|
-
const destFilePath = path.join(resolvedDestDir, header.name);
|
|
134
|
+
const destFilePath = path.join(resolvedDestDir, stripFileName(strip, header.name, header.type));
|
|
131
135
|
const resolvedDestPath = path.resolve(destFilePath);
|
|
132
136
|
|
|
133
137
|
// Security: Validate that the entry path doesn't escape the destination directory
|