Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
fetch-package-metadata: use unpipe
Browse files Browse the repository at this point in the history
for 0.8 compatibility instead of trying to kill the streams by hand

Fixes #8695

PR-URL: #8718
  • Loading branch information
iarna committed Jul 1, 2015
1 parent c1312b8 commit 57c3cea
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/fetch-package-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var iferr = require('iferr')
var rimraf = require('rimraf')
var clone = require('lodash.clonedeep')
var validate = require('aproba')
var unpipe = require('unpipe')

var npm = require('./npm.js')
var mapToRegistry = require('./utils/map-to-registry.js')
Expand Down Expand Up @@ -256,9 +257,9 @@ function untarStream (tarball, cb) {
validate('SF', arguments)
cb = once(cb)

var tounpipe = []
var stream
var file = stream = fs.createReadStream(tarball)
var tounpipe = [file]
file.on('error', function (er) {
er = new Error('Error extracting ' + tarball + ' archive: ' + er.message)
er.code = 'EREADFILE'
Expand Down Expand Up @@ -287,7 +288,7 @@ function untarStream (tarball, cb) {
er.code = 'EGUNZIP'
cb(er)
})
tounpipe.push([stream, gunzip])
tounpipe.push(gunzip)
stream = gunzip
doUntar()
}
Expand All @@ -299,18 +300,19 @@ function untarStream (tarball, cb) {
er.code = 'EUNTAR'
cb(er)
})
tounpipe.push([stream, untar])
tounpipe.push(untar)
stream = untar
addClose()
}

function addClose () {
stream.close = function () {
tounpipe.forEach(function (streams) {
streams[0].unpipe(streams[1])
tounpipe.forEach(function (stream) {
unpipe(stream)
})

file.close()
if (file.close) file.close()
if (file.destroy) file.destroy()
}
}
}

0 comments on commit 57c3cea

Please sign in to comment.