Skip to content

Commit 6e1e425

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: nodejs#1212 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent e6699d1 commit 6e1e425

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
@@ -20,10 +20,8 @@ var fs = require('graceful-fs')
2020
, rm = require('rimraf')
2121
, path = require('path')
2222
, crypto = require('crypto')
23-
, zlib = require('zlib')
2423
, log = require('npmlog')
2524
, semver = require('semver')
26-
, fstream = require('fstream')
2725
, request = require('request')
2826
, mkdir = require('mkdirp')
2927
, processRelease = require('./process-release')
@@ -148,41 +146,33 @@ function install (fs, gyp, argv, callback) {
148146
var tarPath = gyp.opts.tarball
149147
var badDownload = false
150148
, extractCount = 0
151-
, gunzip = zlib.createGunzip()
152-
, extracter = tar.Extract({ path: devDir, strip: 1, filter: isValid })
153149

154150
var contentShasums = {}
155151
var expectShasums = {}
156152

157153
// checks if a file to be extracted from the tarball is valid.
158154
// only .h header files and the gyp files get extracted
159-
function isValid () {
160-
var name = this.path.substring(devDir.length + 1)
161-
var isValid = valid(name)
162-
if (name === '' && this.type === 'Directory') {
163-
// the first directory entry is ok
164-
return true
165-
}
155+
function isValid (path, entry) {
156+
var isValid = valid(path)
166157
if (isValid) {
167-
log.verbose('extracted file from tarball', name)
158+
log.verbose('extracted file from tarball', path)
168159
extractCount++
169160
} else {
170161
// invalid
171-
log.silly('ignoring from tarball', name)
162+
log.silly('ignoring from tarball', path)
172163
}
173164
return isValid
174165
}
175166

176-
gunzip.on('error', cb)
177-
extracter.on('error', cb)
178-
extracter.on('end', afterTarball)
179-
180-
// download the tarball, gunzip and extract!
167+
// download the tarball and extract!
181168

182169
if (tarPath) {
183-
var input = fs.createReadStream(tarPath)
184-
input.pipe(gunzip).pipe(extracter)
185-
return
170+
return tar.extract({
171+
file: tarPath,
172+
strip: 1,
173+
filter: isValid,
174+
cwd: devDir
175+
}).then(afterTarball, cb)
186176
}
187177

188178
try {
@@ -222,7 +212,11 @@ function install (fs, gyp, argv, callback) {
222212
})
223213

224214
// start unzipping and untaring
225-
req.pipe(gunzip).pipe(extracter)
215+
res.pipe(tar.extract({
216+
strip: 1,
217+
cwd: devDir,
218+
filter: isValid
219+
}).on('close', afterTarball).on('error', cb))
226220
})
227221

228222
// 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
"mkdirp": "^0.5.0",
@@ -32,11 +31,11 @@
3231
"request": "^2.87.0",
3332
"rimraf": "2",
3433
"semver": "~5.3.0",
35-
"tar": "^2.0.0",
34+
"tar": "^3.1.3",
3635
"which": "1"
3736
},
3837
"engines": {
39-
"node": ">= 0.8.0"
38+
"node": ">= 4.0.0"
4039
},
4140
"devDependencies": {
4241
"tape": "~4.2.0",

0 commit comments

Comments
 (0)