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

Commit 0731f45

Browse files
fix(get): properly handled nested content
1 parent 0fefbd1 commit 0731f45

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/tar-stream-to-objects.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,36 @@ const Readable = require('readable-stream')
55

66
// transform tar stream into readable stream of
77
// { path: 'string', content: Readable }
8-
module.exports = function (err, res, send, done) {
8+
module.exports = (err, res, send, done) => {
99
if (err) {
1010
return done(err)
1111
}
1212

13-
var ex = tar.extract()
13+
const ex = tar.extract()
1414
res.pipe(ex)
1515

16-
var objStream = new Readable({ objectMode: true })
16+
const objStream = new Readable({ objectMode: true })
1717
objStream._read = function noop () {}
1818

19-
ex.on('entry', function (header, stream, next) {
20-
objStream.push({
21-
path: header.name,
22-
content: header.type !== 'directory' ? stream : null
23-
})
24-
next()
19+
ex.on('entry', (header, stream, next) => {
20+
stream.on('end', next)
21+
22+
if (header.type !== 'directory') {
23+
objStream.push({
24+
path: header.name,
25+
content: stream
26+
})
27+
} else {
28+
objStream.push({
29+
path: header.name
30+
})
31+
stream.resume()
32+
}
2533
})
34+
2635
ex.on('finish', () => {
2736
objStream.push(null)
2837
})
2938

3039
done(null, objStream)
3140
}
32-

0 commit comments

Comments
 (0)