@@ -10,12 +10,19 @@ module.exports = (send) => {
10
10
return {
11
11
get : promisify ( ( args , opts , callback ) => {
12
12
// TODO this needs to be adjusted with the new go-ipfs http-api
13
+ let cid
13
14
if ( CID . isCID ( args ) ) {
15
+ cid = args
14
16
args = multihash . toB58String ( args . multihash )
15
- }
16
- if ( Buffer . isBuffer ( args ) ) {
17
+ } else if ( Buffer . isBuffer ( args ) ) {
18
+ cid = new CID ( args )
17
19
args = multihash . toB58String ( args )
20
+ } else if ( typeof args == 'string' ) {
21
+ cid = new CID ( args )
22
+ } else {
23
+ return callback ( new Error ( 'invalid argument' ) )
18
24
}
25
+
19
26
if ( typeof opts === 'function' ) {
20
27
callback = opts
21
28
opts = { }
@@ -24,13 +31,13 @@ module.exports = (send) => {
24
31
// Transform the response from Buffer or a Stream to a Block
25
32
const transform = ( res , callback ) => {
26
33
if ( Buffer . isBuffer ( res ) ) {
27
- callback ( null , new Block ( res ) )
34
+ callback ( null , new Block ( res , cid ) )
28
35
} else {
29
36
streamToValue ( res , ( err , data ) => {
30
37
if ( err ) {
31
38
return callback ( err )
32
39
}
33
- callback ( null , new Block ( data ) )
40
+ callback ( null , new Block ( data , cid ) )
34
41
} )
35
42
}
36
43
}
@@ -92,7 +99,9 @@ module.exports = (send) => {
92
99
}
93
100
94
101
// Transform the response to a Block
95
- const transform = ( blockInfo , callback ) => callback ( null , new Block ( block ) )
102
+ const transform = ( info , callback ) => {
103
+ callback ( null , new Block ( block , new CID ( info . Key ) ) )
104
+ }
96
105
97
106
send . andTransform ( request , transform , callback )
98
107
} )
0 commit comments