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

Commit

Permalink
fix(get): properly handled nested content
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 8, 2016
1 parent 1d0d57e commit 57796ad
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/tar-stream-to-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 57796ad

Please sign in to comment.