3
3
const promisify = require ( 'promisify-es6' )
4
4
const cleanCID = require ( '../utils/clean-cid' )
5
5
const TarStreamToObjects = require ( '../utils/tar-stream-to-objects' )
6
+ const concat = require ( 'concat-stream' )
7
+ const through = require ( 'through2' )
6
8
const v = require ( 'is-ipfs' )
7
9
8
10
module . exports = ( send ) => {
@@ -14,8 +16,7 @@ module.exports = (send) => {
14
16
15
17
// opts is the real callback --
16
18
// 'callback' is being injected by promisify
17
- if ( typeof opts === 'function' &&
18
- typeof callback === 'function' ) {
19
+ if ( typeof opts === 'function' && typeof callback === 'function' ) {
19
20
callback = opts
20
21
opts = { }
21
22
}
@@ -28,13 +29,23 @@ module.exports = (send) => {
28
29
}
29
30
}
30
31
31
- const request = {
32
- path : 'get' ,
33
- args : path ,
34
- qs : opts
35
- }
32
+ const request = { path : 'get' , args : path , qs : opts }
36
33
37
34
// 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
+ } )
39
50
} )
40
51
}
0 commit comments