diff --git a/package.json b/package.json index 8ab1cee41..62a352b4b 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "chai": "^3.5.0", "gulp": "^3.9.1", "hapi": "^15.2.0", - "interface-ipfs-core": "^0.18.0", + "interface-ipfs-core": "^0.18.2", "ipfsd-ctl": "^0.17.0", "pre-commit": "^1.1.3", "socket.io": "^1.5.1", diff --git a/src/tar-stream-to-objects.js b/src/tar-stream-to-objects.js index b817d5612..acab14658 100644 --- a/src/tar-stream-to-objects.js +++ b/src/tar-stream-to-objects.js @@ -5,28 +5,34 @@ 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() - 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 + res + .pipe(tar.extract()) + .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() + } + }) + .on('finish', () => { + objStream.push(null) }) - next() - }) - ex.on('finish', () => { - objStream.push(null) - }) done(null, objStream) } -