33const promisify = require ( 'promisify-es6' )
44const bl = require ( 'bl' )
55const Block = require ( 'ipfs-block' )
6+ const multihash = require ( 'multihashes' )
67
78module . exports = ( send ) => {
89 return {
910 get : promisify ( ( args , opts , callback ) => {
11+ // TODO this needs to be adjusted with the new go-ipfs
12+ // http-api
13+ if ( args && args . constructor && args . constructor . name === 'CID' ) {
14+ args = multihash . toB58String ( args . multihash )
15+ }
1016 if ( typeof ( opts ) === 'function' ) {
1117 callback = opts
1218 opts = { }
1319 }
20+
1421 return send ( {
1522 path : 'block/get' ,
1623 args : args ,
@@ -32,6 +39,12 @@ module.exports = (send) => {
3239 } )
3340 } ) ,
3441 stat : promisify ( ( args , opts , callback ) => {
42+ // TODO this needs to be adjusted with the new go-ipfs
43+ // http-api
44+ if ( args && args . constructor && args . constructor . name === 'CID' ) {
45+ args = multihash . toB58String ( args . multihash )
46+ }
47+
3548 if ( typeof ( opts ) === 'function' ) {
3649 callback = opts
3750 opts = { }
@@ -50,7 +63,15 @@ module.exports = (send) => {
5063 } )
5164 } )
5265 } ) ,
53- put : promisify ( ( block , callback ) => {
66+ put : promisify ( ( block , cid , callback ) => {
67+ // TODO this needs to be adjusted with the new go-ipfs
68+ // http-api
69+
70+ if ( typeof ( cid ) === 'function' ) {
71+ callback = cid
72+ cid = { }
73+ }
74+
5475 if ( Array . isArray ( block ) ) {
5576 const err = new Error ( 'block.put() only accepts 1 file' )
5677 return callback ( err )
0 commit comments