@@ -15,10 +15,8 @@ var fs = require('graceful-fs')
15
15
, rm = require ( 'rimraf' )
16
16
, path = require ( 'path' )
17
17
, crypto = require ( 'crypto' )
18
- , zlib = require ( 'zlib' )
19
18
, log = require ( 'npmlog' )
20
19
, semver = require ( 'semver' )
21
- , fstream = require ( 'fstream' )
22
20
, request = require ( 'request' )
23
21
, minimatch = require ( 'minimatch' )
24
22
, mkdir = require ( 'mkdirp' )
@@ -144,41 +142,33 @@ function install (gyp, argv, callback) {
144
142
var tarPath = gyp . opts . tarball
145
143
var badDownload = false
146
144
, extractCount = 0
147
- , gunzip = zlib . createGunzip ( )
148
- , extracter = tar . Extract ( { path : devDir , strip : 1 , filter : isValid } )
149
145
150
146
var contentShasums = { }
151
147
var expectShasums = { }
152
148
153
149
// checks if a file to be extracted from the tarball is valid.
154
150
// only .h header files and the gyp files get extracted
155
- function isValid ( ) {
156
- var name = this . path . substring ( devDir . length + 1 )
157
- var isValid = valid ( name )
158
- if ( name === '' && this . type === 'Directory' ) {
159
- // the first directory entry is ok
160
- return true
161
- }
151
+ function isValid ( path , entry ) {
152
+ var isValid = valid ( path )
162
153
if ( isValid ) {
163
- log . verbose ( 'extracted file from tarball' , name )
154
+ log . verbose ( 'extracted file from tarball' , path )
164
155
extractCount ++
165
156
} else {
166
157
// invalid
167
- log . silly ( 'ignoring from tarball' , name )
158
+ log . silly ( 'ignoring from tarball' , path )
168
159
}
169
160
return isValid
170
161
}
171
162
172
- gunzip . on ( 'error' , cb )
173
- extracter . on ( 'error' , cb )
174
- extracter . on ( 'end' , afterTarball )
175
-
176
- // download the tarball, gunzip and extract!
163
+ // download the tarball and extract!
177
164
178
165
if ( tarPath ) {
179
- var input = fs . createReadStream ( tarPath )
180
- input . pipe ( gunzip ) . pipe ( extracter )
181
- return
166
+ return tar . extract ( {
167
+ file : tarPath ,
168
+ strip : 1 ,
169
+ filter : isValid ,
170
+ cwd : devDir
171
+ } ) . then ( afterTarball , cb )
182
172
}
183
173
184
174
try {
@@ -218,7 +208,11 @@ function install (gyp, argv, callback) {
218
208
} )
219
209
220
210
// start unzipping and untaring
221
- req . pipe ( gunzip ) . pipe ( extracter )
211
+ res . pipe ( tar . extract ( {
212
+ strip : 1 ,
213
+ cwd : devDir ,
214
+ filter : isValid
215
+ } ) . on ( 'close' , _ => setTimeout ( afterTarball , 1000 ) ) . on ( 'error' , cb ) )
222
216
} )
223
217
224
218
// invoked after the tarball has finished being extracted
0 commit comments