Skip to content
This repository was archived by the owner on Aug 23, 2021. It is now read-only.

Commit

Permalink
Updates the API docs to reflect the new endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hazmatzo committed Aug 6, 2019
1 parent 3e3c63e commit fc8a4b9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* paych.redeem
* paych.voucher
* [ping](#ping)
* retrievalClient.retrievePiece
* [retrievalClient.retrievePiece](#retrievalclientretrievepiece)
* [show.block](#showblock)
* [stats.bandwidth](#statsbandwidth)
* [swarm.connect](#swarmconnect)
Expand Down Expand Up @@ -847,6 +847,35 @@ After first iteration:
*/
```

## `retrievalClient.retrievePiece`

> Read out piece data stored by a miner on the network
### `retrievalClient.retrievePiece(miner, cid, [options])`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| miner address | `String` | Retrieval miner actor address |
| cid | `String` | Content identifier of piece to read |
| options | `Object` | Optional options |
| options.signal | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | A signal that can be used to abort the request |

#### Returns

| Type | Description |
|------|-------------|
| `AsyncIterable<Buffer\|UInt8Array>` | Content of the file, yields `Buffer` objects in Node.js and `UInt8Array` objects in the browser |

#### Example

```js
let data = Buffer.alloc(0)
for await (const chunk of fc.retrievalClient.retrievePiece('t2u2r6nyaxdspozci5t2i2xtfw23lxa35rvkul7di','QmSB6t4fVfE4fZ46EFBodtK89RJaCRTtPRaEYFx8EQxh8a'))
data = Buffer.concat([data, chunk])
```

## `show.block`

> Show a filecoin block by its CID
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmd/retrieval-client/retrieve-piece.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ test('should read out piece data stored by a miner on the network', async t => {
}

t.deepEqual(data, Buffer.concat(chunks))
})
})

0 comments on commit fc8a4b9

Please sign in to comment.