-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs: update block api documentation #4124
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -39,6 +39,7 @@ An optional object which may have the following keys: | |||||||||||
| ---- | ---- | ------- | ----------- | | ||||||||||||
| timeout | `Number` | `undefined` | A timeout in ms | | ||||||||||||
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | | ||||||||||||
| preload | `boolean` | `false` | Whether to preload all blocks created during this operation | | ||||||||||||
|
||||||||||||
### Returns | ||||||||||||
|
||||||||||||
|
@@ -63,7 +64,7 @@ A great source of [examples][] can be found in the tests for this API. | |||||||||||
|
||||||||||||
| Name | Type | Description | | ||||||||||||
| ---- | ---- | ----------- | | ||||||||||||
| block | A `Uint8Array` or [Block][] instance | The block or data to store | | ||||||||||||
| block | `Uint8Array` | The block of data to store | | ||||||||||||
hacdias marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
### Options | ||||||||||||
|
||||||||||||
|
@@ -73,19 +74,18 @@ An optional object which may have the following keys: | |||||||||||
| ---- | ---- | ------- | ----------- | | ||||||||||||
| format | `String` | `'dag-pb'` | The codec to use to create the CID | | ||||||||||||
| mhtype | `String` | `sha2-256` | The hashing algorithm to use to create the CID | | ||||||||||||
| mhlen | `Number` | | | | ||||||||||||
| mhlen | `Number` | `undefined` | The hash length (only relevant for `go-ipfs`) | | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core-types/src/block/index.ts does not include this option. However, the js-ipfs/packages/ipfs-cli/src/commands/block/put.js Lines 34 to 37 in 548cfb2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not supported by If you could find out the what and the why maybe we could even remove it entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it seems to be literally the multihash length, but doesn't seem to be very useful looking at the very limited search results. I tried figuring out if this was useful when opening this PR, but couldn't find anything that explained why it may be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to refactor relevant go-ipfs code around this recently and can provide some details. afaik the only place where this is used, is when tldr:
|
||||||||||||
| version | `Number` | `0` | The version to use to create the CID | | ||||||||||||
| pin | `boolean` | `false` | If true, pin added blocks recursively | | ||||||||||||
| timeout | `Number` | `undefined` | A timeout in ms | | ||||||||||||
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | | ||||||||||||
|
||||||||||||
**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. | ||||||||||||
| preload | `boolean` | `false` | Whether to preload all blocks created during this operation | | ||||||||||||
hacdias marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
### Returns | ||||||||||||
|
||||||||||||
| Type | Description | | ||||||||||||
| -------- | -------- | | ||||||||||||
| `Promise<Block>` | A [Block][block] type object, containing both the data and the hash of the block | | ||||||||||||
| `Promise<CID>` | A [CID][CID] type object containing the hash of the block | | ||||||||||||
hacdias marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
### Example | ||||||||||||
|
||||||||||||
|
@@ -96,21 +96,6 @@ const decoder = new TextDecoder() | |||||||||||
|
||||||||||||
const block = await ipfs.block.put(buf) | ||||||||||||
|
||||||||||||
console.log(decoder.decode(block.data)) | ||||||||||||
// Logs: | ||||||||||||
// a serialized object | ||||||||||||
console.log(block.cid.toString()) | ||||||||||||
// Logs: | ||||||||||||
// the CID of the object | ||||||||||||
|
||||||||||||
// With custom format and hashtype through CID | ||||||||||||
import { CID } from 'multiformats/cid' | ||||||||||||
import * as dagPB from '@ipld/dag-pb' | ||||||||||||
const buf = new TextEncoder().encode('another serialized object') | ||||||||||||
const cid = CID.createV1(dagPB.code, multihash) | ||||||||||||
|
||||||||||||
const block = await ipfs.block.put(blob, cid) | ||||||||||||
hacdias marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
console.log(decoder.decode(block.data)) | ||||||||||||
// Logs: | ||||||||||||
// a serialized object | ||||||||||||
|
@@ -191,6 +176,7 @@ An optional object which may have the following keys: | |||||||||||
| ---- | ---- | ------- | ----------- | | ||||||||||||
| timeout | `Number` | `undefined` | A timeout in ms | | ||||||||||||
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | | ||||||||||||
| preload | `boolean` | `false` | Whether to preload all blocks created during this operation | | ||||||||||||
hacdias marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
### Returns | ||||||||||||
|
||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.