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