@@ -12,6 +12,7 @@ const utils = require('../utils');
1212let iconv ;
1313
1414const YAUZL_CALLBACK = Symbol ( 'ZipUncompressStream#yauzlCallback' ) ;
15+ const STRIP_NAME = Symbol ( 'ZipUncompressStream#stripName' ) ;
1516
1617// don't decodeStrings on yauzl, we should handle fileName by ourself
1718// see validateFileName on https://github.com/thejoshwolfe/yauzl/blob/51010ce4e8c7e6345efe195e1b4150518f37b393/index.js#L607
@@ -33,6 +34,7 @@ class ZipUncompressStream extends UncompressBaseStream {
3334 super ( opts ) ;
3435
3536 this . _chunks = [ ] ;
37+ this . _strip = Number ( opts . strip ) || 0 ;
3638 this . _zipFileNameEncoding = opts . zipFileNameEncoding || 'utf8' ;
3739 if ( this . _zipFileNameEncoding === 'utf-8' ) {
3840 this . _zipFileNameEncoding = 'utf8' ;
@@ -106,7 +108,7 @@ class ZipUncompressStream extends UncompressBaseStream {
106108 }
107109 // directory file names end with '/' (for Linux and macOS) or '\' (for Windows)
108110 const type = / [ \\ \/ ] $ / . test ( entry . fileName ) ? 'directory' : 'file' ;
109- const name = entry . fileName ;
111+ const name = entry . fileName = this [ STRIP_NAME ] ( entry . fileName , type ) ;
110112
111113 const header = { name, type, yauzl : entry , mode } ;
112114
@@ -133,6 +135,10 @@ class ZipUncompressStream extends UncompressBaseStream {
133135 zipFile . readEntry ( ) ;
134136 }
135137 }
138+
139+ [ STRIP_NAME ] ( fileName , type ) {
140+ return utils . stripFileName ( this . _strip , fileName , type ) ;
141+ }
136142}
137143
138144module . exports = ZipUncompressStream ;
0 commit comments