This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 2 files changed +38
-8
lines changed
2 files changed +38
-8
lines changed Original file line number Diff line number Diff line change 24
24
"detect-node" : " ^2.0.3" ,
25
25
"flatmap" : " 0.0.3" ,
26
26
"glob" : " ^7.0.5" ,
27
+ "ipfs-block" : " ^0.3.0" ,
27
28
"ipfs-merkle-dag" : " ^0.6.0" ,
28
29
"is-ipfs" : " ^0.2.0" ,
29
30
"isstream" : " ^0.1.2" ,
47
48
"chai" : " ^3.5.0" ,
48
49
"gulp" : " ^3.9.1" ,
49
50
"hapi" : " ^14.1.0" ,
50
- "interface-ipfs-core" : " ^0.13 .0" ,
51
+ "interface-ipfs-core" : " ^0.14 .0" ,
51
52
"ipfsd-ctl" : " ^0.14.0" ,
52
53
"pre-commit" : " ^1.1.3" ,
53
54
"socket.io" : " ^1.4.8" ,
99
100
"url" : " https://github.com./ipfs/js-ipfs-api/issues"
100
101
},
101
102
"homepage" : " https://github.com./ipfs/js-ipfs-api"
102
- }
103
+ }
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const promisify = require ( 'promisify-es6' )
4
+ const bl = require ( 'bl' )
5
+ const Block = require ( 'ipfs-block' )
4
6
5
7
module . exports = ( send ) => {
6
8
return {
@@ -13,7 +15,17 @@ module.exports = (send) => {
13
15
path : 'block/get' ,
14
16
args : args ,
15
17
qs : opts
16
- } , callback )
18
+ } , ( err , res ) => {
19
+ if ( err ) {
20
+ return callback ( err )
21
+ }
22
+ res . pipe ( bl ( ( err , data ) => {
23
+ if ( err ) {
24
+ return callback ( err )
25
+ }
26
+ callback ( null , new Block ( data ) )
27
+ } ) )
28
+ } )
17
29
} ) ,
18
30
stat : promisify ( ( args , opts , callback ) => {
19
31
if ( typeof ( opts ) === 'function' ) {
@@ -24,18 +36,35 @@ module.exports = (send) => {
24
36
path : 'block/stat' ,
25
37
args : args ,
26
38
qs : opts
27
- } , callback )
39
+ } , ( err , stats ) => {
40
+ if ( err ) {
41
+ return callback ( err )
42
+ }
43
+ callback ( null , {
44
+ key : stats . Key ,
45
+ size : stats . Size
46
+ } )
47
+ } )
28
48
} ) ,
29
- put : promisify ( ( file , callback ) => {
30
- if ( Array . isArray ( file ) ) {
49
+ put : promisify ( ( block , callback ) => {
50
+ if ( Array . isArray ( block ) ) {
31
51
const err = new Error ( 'block.put() only accepts 1 file' )
32
52
return callback ( err )
33
53
}
34
54
55
+ if ( typeof block === 'object' && block . data ) {
56
+ block = block . data
57
+ }
58
+
35
59
return send ( {
36
60
path : 'block/put' ,
37
- files : file
38
- } , callback )
61
+ files : block
62
+ } , ( err , blockInfo ) => {
63
+ if ( err ) {
64
+ return callback ( err )
65
+ }
66
+ callback ( null , new Block ( block ) )
67
+ } )
39
68
} )
40
69
}
41
70
}
You can’t perform that action at this time.
0 commit comments