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

Commit 6cdbaf9

Browse files
committed
.get
1 parent d1d3915 commit 6cdbaf9

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/files/get.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const promisify = require('promisify-es6')
44
const cleanCID = require('../utils/clean-cid')
55
const TarStreamToObjects = require('../utils/tar-stream-to-objects')
6+
const concat = require('concat-stream')
7+
const through = require('through2')
68
const v = require('is-ipfs')
79

810
module.exports = (send) => {
@@ -14,8 +16,7 @@ module.exports = (send) => {
1416

1517
// opts is the real callback --
1618
// 'callback' is being injected by promisify
17-
if (typeof opts === 'function' &&
18-
typeof callback === 'function') {
19+
if (typeof opts === 'function' && typeof callback === 'function') {
1920
callback = opts
2021
opts = {}
2122
}
@@ -28,13 +29,23 @@ module.exports = (send) => {
2829
}
2930
}
3031

31-
const request = {
32-
path: 'get',
33-
args: path,
34-
qs: opts
35-
}
32+
const request = { path: 'get', args: path, qs: opts }
3633

3734
// Convert the response stream to TarStream objects
38-
send.andTransform(request, TarStreamToObjects, callback)
35+
send.andTransform(request, TarStreamToObjects, (err, stream) => {
36+
if (err) { return callback(err) }
37+
38+
const files = []
39+
stream.pipe(through.obj((file, enc, next) => {
40+
if (file.content) {
41+
file.content.pipe(concat((content) => {
42+
files.push({ path: file.path, content: content })
43+
}))
44+
} else {
45+
files.push(file)
46+
}
47+
next()
48+
}, () => callback(null, files)))
49+
})
3950
})
4051
}

0 commit comments

Comments
 (0)