diff --git a/src/tar-stream-to-objects.js b/src/tar-stream-to-objects.js index b817d5612..9630c72f2 100644 --- a/src/tar-stream-to-objects.js +++ b/src/tar-stream-to-objects.js @@ -5,28 +5,36 @@ const Readable = require('readable-stream') // transform tar stream into readable stream of // { path: 'string', content: Readable } -module.exports = function (err, res, send, done) { +module.exports = (err, res, send, done) => { if (err) { return done(err) } - var ex = tar.extract() + const ex = tar.extract() res.pipe(ex) - var objStream = new Readable({ objectMode: true }) + const objStream = new Readable({ objectMode: true }) objStream._read = function noop () {} - ex.on('entry', function (header, stream, next) { - objStream.push({ - path: header.name, - content: header.type !== 'directory' ? stream : null - }) - next() + ex.on('entry', (header, stream, next) => { + stream.on('end', next) + + if (header.type !== 'directory') { + objStream.push({ + path: header.name, + content: stream + }) + } else { + objStream.push({ + path: header.name + }) + stream.resume() + } }) + ex.on('finish', () => { objStream.push(null) }) done(null, objStream) } -