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

Commit

Permalink
install: Make shrinkwrap extraction work in 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Jun 26, 2015
1 parent 8fb8b4a commit bc46ca9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/fetch-package-metadata.js
Expand Up @@ -253,6 +253,11 @@ function hasTarHeader (c) {
c[264] === 0x00))
}

function dispose (stream) {
if (stream.destroy) return stream.destroy()
if (stream.close) return stream.close()
}

function untarStream (tarball, cb) {
validate('SF', arguments)
cb = once(cb)
Expand All @@ -273,7 +278,7 @@ function untarStream (tarball, cb) {
doUntar()
}
else {
file.close()
dispose(file)
var er = new Error('Non-gzip/tarball ' + tarball)
er.code = 'ENOTTARBALL'
return cb(er)
Expand All @@ -290,7 +295,7 @@ function untarStream (tarball, cb) {
er.code = 'EGUNZIP'
cb(er)
})
tounpipe.push([stream, gunzip])
tounpipe.push(gunzip)
stream = gunzip
doUntar()
}
Expand All @@ -302,18 +307,16 @@ 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(dispose)

file.close()
dispose(file)
}
}
}

0 comments on commit bc46ca9

Please sign in to comment.