Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #384 from ipfs/fix-get
Browse files Browse the repository at this point in the history
fix(get): properly handled nested content
  • Loading branch information
daviddias authored Nov 8, 2016
2 parents 505ce8e + 1191bb6 commit 9d3889d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 21 additions & 15 deletions src/tar-stream-to-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 9d3889d

Please sign in to comment.