You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
|`Promise<Object>`| An object representing the wantlist |
11
20
12
-
`callback` must follow `function (err, list) {}` signature, where `err` is an error if the operation was not successful. `list` is an Object containing the following keys:
21
+
the returned object contains the following keys:
13
22
14
23
-`Keys` An array of objects containing the following keys:
15
24
-`/` A string multihash
16
25
17
-
If no `callback` is passed, a promise is returned.
A great source of [examples][] can be found in the tests for this API.
39
+
31
40
#### `bitswap.stat`
32
41
33
42
> Show diagnostic information on the bitswap agent.
34
43
35
-
##### `ipfs.bitswap.stat([callback])`
44
+
##### `ipfs.bitswap.stat()`
36
45
37
46
Note: `bitswap.stat` and `stats.bitswap` can be used interchangeably.
38
47
39
-
`callback` must follow `function (err, stats) {}` signature, where `err` is an error if the operation was not successful. `stats` is an Object containing the following keys:
48
+
**Returns**
49
+
50
+
| Type | Description |
51
+
| -------- | -------- |
52
+
|`Promise<Object>`| An object that contains information about the bitswap agent |
53
+
54
+
the returned object contains the following keys:
40
55
41
56
-`provideBufLen` is an integer.
42
57
-`wantlist` (array of CIDs)
@@ -48,14 +63,13 @@ Note: `bitswap.stat` and `stats.bitswap` can be used interchangeably.
48
63
-`dupBlksReceived` is a [BigNumber Int][1]
49
64
-`dupDataReceived` is a [BigNumber Int][1]
50
65
51
-
If no `callback` is passed, a promise is returned.
- String, the base58 encoded version of the multihash
19
22
20
-
`callback` must follow `function (err, block) {}` signature, where `err` is an error if the operation was not successful and `block` is a [Block][block] type object, containing both the data and the hash of the block.
23
+
**Returns**
21
24
22
-
If no `callback` is passed, a promise is returned.
25
+
| Type | Description |
26
+
| -------- | -------- |
27
+
|`Promise<Block>`| A [Block][block] type object, containing both the data and the hash of the block |
23
28
24
29
**Example:**
25
30
26
31
```JavaScript
27
-
ipfs.block.get(cid, function (err, block) {
28
-
if (err) {
29
-
throw err
30
-
}
31
-
block.key((err, key) => {
32
-
if (err) {
33
-
throw err
34
-
}
35
-
console.log(key, block.data)
36
-
})
37
-
})
32
+
constblock=awaitipfs.block.get(cid)
33
+
console.log(block.data)
38
34
```
39
35
40
36
A great source of [examples][] can be found in the tests for this API.
@@ -43,7 +39,7 @@ A great source of [examples][] can be found in the tests for this API.
@@ -65,44 +61,40 @@ if no options are passed, it defaults to `{ format: 'dag-pb', mhtype: 'sha2-256'
65
61
66
62
**Note:** If you pass a [`Block`][block] instance as the block parameter, you don't need to pass options, as the block instance will carry the CID value as a property.
67
63
68
-
`callback` has the signature `function (err, block) {}`, where `err` is an error if the operation was not successful and `block` is a [Block][block] type object, containing both the data and the hash of the block.
64
+
**Returns**
69
65
70
-
If no `callback` is passed, a promise is returned.
66
+
| Type | Description |
67
+
| -------- | -------- |
68
+
|`Promise<Block>`| A [Block][block] type object, containing both the data and the hash of the block |
71
69
72
70
**Example:**
73
71
74
72
```JavaScript
75
73
// Defaults
76
74
constbuf=newBuffer('a serialized object')
77
75
78
-
ipfs.block.put(buf, (err, block) => {
79
-
if (err) { throw err }
80
-
// Block has been stored
76
+
constblock=awaitipfs.block.put(buf)
81
77
82
-
console.log(block.data.toString())
83
-
// Logs:
84
-
// a serialized object
85
-
console.log(block.cid.toBaseEncodedString())
86
-
// Logs:
87
-
// the CID of the object
88
-
})
78
+
console.log(block.data.toString())
79
+
// Logs:
80
+
// a serialized object
81
+
console.log(block.cid.toString())
82
+
// Logs:
83
+
// the CID of the object
89
84
90
85
// With custom format and hashtype through CID
91
86
constCID=require('cids')
92
87
constbuf=newBuffer('another serialized object')
93
88
constcid=newCID(1, 'dag-pb', multihash)
94
89
95
-
ipfs.block.put(blob, cid, (err, block) => {
96
-
if (err) { throw err }
97
-
// Block has been stored
98
-
99
-
console.log(block.data.toString())
100
-
// Logs:
101
-
// a serialized object
102
-
console.log(block.cid.toBaseEncodedString())
103
-
// Logs:
104
-
// the CID of the object
105
-
})
90
+
constblock=awaitipfs.block.put(blob, cid)
91
+
92
+
console.log(block.data.toString())
93
+
// Logs:
94
+
// a serialized object
95
+
console.log(block.cid.toString())
96
+
// Logs:
97
+
// the CID of the object
106
98
```
107
99
108
100
A great source of [examples][] can be found in the tests for this API.
@@ -111,7 +103,7 @@ A great source of [examples][] can be found in the tests for this API.
111
103
112
104
> Remove one or more IPFS block(s).
113
105
114
-
##### `ipfs.block.rm(cid, [options], [callback])`
106
+
##### `ipfs.block.rm(cid, [options])`
115
107
116
108
`cid` is a [cid][cid] which can be passed as:
117
109
@@ -125,21 +117,19 @@ A great source of [examples][] can be found in the tests for this API.
125
117
- force (boolean): Ignores nonexistent blocks.
126
118
- quiet (boolean): write minimal output
127
119
128
-
`callback` must follow `function (err, result) {}` signature, where `err` is an error if the operation was not successful and `result` is a list of objects, containing hash and (potentially) error strings.
120
+
**Returns**
129
121
130
-
If an error string is present for a given object in `result`, the block with that hash was not removed and the string will contain the reason why, for example if the block was pinned.
122
+
| Type | Description |
123
+
| -------- | -------- |
124
+
|`Promise<Array>`| An array of objects containing hash and (potentially) error strings |
131
125
132
-
If no `callback`is passed, a promise is returned.
126
+
Note: If an error string is present for a given object in the returned array, the block with that hash was not removed and the string will contain the reason why, for example if the block was pinned.
133
127
134
128
**Example:**
135
129
136
130
```JavaScript
137
-
ipfs.block.rm(cid, function (err, result) {
138
-
if (err) {
139
-
throw err
140
-
}
141
-
console.log(result[0].hash)
142
-
})
131
+
constresult=awaitipfs.block.rm(cid)
132
+
console.log(result[0].hash)
143
133
```
144
134
145
135
A great source of [examples][] can be found in the tests for this API.
@@ -148,15 +138,21 @@ A great source of [examples][] can be found in the tests for this API.
148
138
149
139
> Print information of a raw IPFS block.
150
140
151
-
##### `ipfs.block.stat(cid, [callback])`
141
+
##### `ipfs.block.stat(cid)`
152
142
153
143
`cid` is a [cid][cid] which can be passed as:
154
144
155
145
-`Buffer`, the raw Buffer of the multihash (or of and encoded version)
156
146
-`String`, the toString version of the multihash (or of an encoded version)
157
147
- CID, a CID instance
158
148
159
-
`callback` must follow the signature `function (err, stats) {}`, where `err` is an error if the operation was not successful and `stats` is an object with the format:`
149
+
**Returns**
150
+
151
+
| Type | Description |
152
+
| -------- | -------- |
153
+
|`Promise<Object>`| An object containing the block's info |
154
+
155
+
the returned object has the following keys:
160
156
161
157
```JavaScript
162
158
{
@@ -165,25 +161,19 @@ A great source of [examples][] can be found in the tests for this API.
165
161
}
166
162
```
167
163
168
-
If no `callback` is passed, a promise is returned.
0 commit comments