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

Commit 9d3889d

Browse files
authored
Merge pull request #384 from ipfs/fix-get
fix(get): properly handled nested content
2 parents 505ce8e + 1191bb6 commit 9d3889d

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"chai": "^3.5.0",
6161
"gulp": "^3.9.1",
6262
"hapi": "^15.2.0",
63-
"interface-ipfs-core": "^0.18.0",
63+
"interface-ipfs-core": "^0.18.2",
6464
"ipfsd-ctl": "^0.17.0",
6565
"pre-commit": "^1.1.3",
6666
"socket.io": "^1.5.1",

src/tar-stream-to-objects.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@ 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()
14-
res.pipe(ex)
15-
16-
var objStream = new Readable({ objectMode: true })
13+
const objStream = new Readable({ objectMode: true })
1714
objStream._read = function noop () {}
1815

19-
ex.on('entry', function (header, stream, next) {
20-
objStream.push({
21-
path: header.name,
22-
content: header.type !== 'directory' ? stream : null
16+
res
17+
.pipe(tar.extract())
18+
.on('entry', (header, stream, next) => {
19+
stream.on('end', next)
20+
21+
if (header.type !== 'directory') {
22+
objStream.push({
23+
path: header.name,
24+
content: stream
25+
})
26+
} else {
27+
objStream.push({
28+
path: header.name
29+
})
30+
stream.resume()
31+
}
32+
})
33+
.on('finish', () => {
34+
objStream.push(null)
2335
})
24-
next()
25-
})
26-
ex.on('finish', () => {
27-
objStream.push(null)
28-
})
2936

3037
done(null, objStream)
3138
}
32-

0 commit comments

Comments
 (0)