Skip to content

Commit 5f924ce

Browse files
isaacsrefack
authored andcommitted
Upgrade to tar v3
Tar version 3 performs better and is more well tested than its predecessor. npm will be using this in the near future, so there is no benefit in shipping a node-gyp that uses the slower and less reliable fstream-based tar. This drops support for node 0.x, and thus should be considered a breaking semver-major change. PR-URL: #1212 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent b5b52f7 commit 5f924ce

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

lib/install.js

+16-22
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ var fs = require('graceful-fs')
1515
, rm = require('rimraf')
1616
, path = require('path')
1717
, crypto = require('crypto')
18-
, zlib = require('zlib')
1918
, log = require('npmlog')
2019
, semver = require('semver')
21-
, fstream = require('fstream')
2220
, request = require('request')
2321
, minimatch = require('minimatch')
2422
, mkdir = require('mkdirp')
@@ -144,41 +142,33 @@ function install (gyp, argv, callback) {
144142
var tarPath = gyp.opts.tarball
145143
var badDownload = false
146144
, extractCount = 0
147-
, gunzip = zlib.createGunzip()
148-
, extracter = tar.Extract({ path: devDir, strip: 1, filter: isValid })
149145

150146
var contentShasums = {}
151147
var expectShasums = {}
152148

153149
// checks if a file to be extracted from the tarball is valid.
154150
// 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)
162153
if (isValid) {
163-
log.verbose('extracted file from tarball', name)
154+
log.verbose('extracted file from tarball', path)
164155
extractCount++
165156
} else {
166157
// invalid
167-
log.silly('ignoring from tarball', name)
158+
log.silly('ignoring from tarball', path)
168159
}
169160
return isValid
170161
}
171162

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!
177164

178165
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)
182172
}
183173

184174
try {
@@ -218,7 +208,11 @@ function install (gyp, argv, callback) {
218208
})
219209

220210
// 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', afterTarball).on('error', cb))
222216
})
223217

224218
// invoked after the tarball has finished being extracted

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"bin": "./bin/node-gyp.js",
2323
"main": "./lib/node-gyp.js",
2424
"dependencies": {
25-
"fstream": "^1.0.0",
2625
"glob": "^7.0.3",
2726
"graceful-fs": "^4.1.2",
2827
"minimatch": "^3.0.2",
@@ -33,11 +32,11 @@
3332
"request": "2",
3433
"rimraf": "2",
3534
"semver": "~5.3.0",
36-
"tar": "^2.0.0",
35+
"tar": "^3.1.3",
3736
"which": "1"
3837
},
3938
"engines": {
40-
"node": ">= 0.8.0"
39+
"node": ">= 4.0.0"
4140
},
4241
"devDependencies": {
4342
"tape": "~4.2.0",

0 commit comments

Comments
 (0)