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

fix(get): properly handled nested content #384

Merged
merged 3 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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)
}