Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 97430f8

Browse files
authored
docs: update block api documentation (#4124)
1 parent 548cfb2 commit 97430f8

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

docs/core-api/BLOCK.md

+6-20
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ An optional object which may have the following keys:
3939
| ---- | ---- | ------- | ----------- |
4040
| timeout | `Number` | `undefined` | A timeout in ms |
4141
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
42+
| preload | `boolean` | `false` | Whether to preload all blocks created during this operation |
4243

4344
### Returns
4445

@@ -63,7 +64,7 @@ A great source of [examples][] can be found in the tests for this API.
6364

6465
| Name | Type | Description |
6566
| ---- | ---- | ----------- |
66-
| block | A `Uint8Array` or [Block][] instance | The block or data to store |
67+
| block | `Uint8Array` | The block of data to store |
6768

6869
### Options
6970

@@ -73,19 +74,18 @@ An optional object which may have the following keys:
7374
| ---- | ---- | ------- | ----------- |
7475
| format | `String` | `'dag-pb'` | The codec to use to create the CID |
7576
| mhtype | `String` | `sha2-256` | The hashing algorithm to use to create the CID |
76-
| mhlen | `Number` | | |
77+
| mhlen | `Number` | `undefined` | The hash length (only relevant for `go-ipfs`) |
7778
| version | `Number` | `0` | The version to use to create the CID |
7879
| pin | `boolean` | `false` | If true, pin added blocks recursively |
7980
| timeout | `Number` | `undefined` | A timeout in ms |
8081
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
81-
82-
**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.
82+
| preload | `boolean` | `false` | Whether to preload all blocks created during this operation |
8383

8484
### Returns
8585

8686
| Type | Description |
8787
| -------- | -------- |
88-
| `Promise<Block>` | A [Block][block] type object, containing both the data and the hash of the block |
88+
| `Promise<CID>` | A [CID][CID] type object containing the hash of the block |
8989

9090
### Example
9191

@@ -96,21 +96,6 @@ const decoder = new TextDecoder()
9696

9797
const block = await ipfs.block.put(buf)
9898

99-
console.log(decoder.decode(block.data))
100-
// Logs:
101-
// a serialized object
102-
console.log(block.cid.toString())
103-
// Logs:
104-
// the CID of the object
105-
106-
// With custom format and hashtype through CID
107-
import { CID } from 'multiformats/cid'
108-
import * as dagPB from '@ipld/dag-pb'
109-
const buf = new TextEncoder().encode('another serialized object')
110-
const cid = CID.createV1(dagPB.code, multihash)
111-
112-
const block = await ipfs.block.put(blob, cid)
113-
11499
console.log(decoder.decode(block.data))
115100
// Logs:
116101
// a serialized object
@@ -191,6 +176,7 @@ An optional object which may have the following keys:
191176
| ---- | ---- | ------- | ----------- |
192177
| timeout | `Number` | `undefined` | A timeout in ms |
193178
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
179+
| preload | `boolean` | `false` | Whether to preload all blocks created during this operation |
194180

195181
### Returns
196182

packages/ipfs-core-types/src/block/index.ts

-13
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,6 @@ export interface API<OptionExtension = {}> {
3232
* console.log(block.cid.toString())
3333
* // Logs:
3434
* // the CID of the object
35-
*
36-
* // With custom format and hashtype through CID
37-
* import { CID } from 'multiformats/cid'
38-
* const another = encoder.encode('another serialized object')
39-
* const cid = CID.createV1(dagPB.code, multihash)
40-
* const block = await ipfs.block.put(another, cid)
41-
* console.log(decoder.decode(block.data))
42-
*
43-
* // Logs:
44-
* // a serialized object
45-
* console.log(block.cid.toString())
46-
* // Logs:
47-
* // the CID of the object
4835
* ```
4936
*/
5037
put: (block: Uint8Array, options?: PutOptions & OptionExtension) => Promise<CID>

0 commit comments

Comments
 (0)