@helia/block-brokers 4.2.4 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,68 @@
13
13
 
14
14
  > Block brokers for Helia
15
15
 
16
+ # About
17
+
18
+ <!--
19
+
20
+ !IMPORTANT!
21
+
22
+ Everything in this README between "# About" and "# Install" is automatically
23
+ generated and will be overwritten the next time the doc generator is run.
24
+
25
+ To make changes to this section, please update the @packageDocumentation section
26
+ of src/index.js or src/index.ts
27
+
28
+ To experiment with formatting, please run "npm run docs" from the root of this
29
+ repo and examine the changes made.
30
+
31
+ -->
32
+
33
+ This module contains Helia block brokers, currently for [bitswap](https://docs.ipfs.tech/concepts/bitswap/)
34
+ and [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
35
+
36
+ ## Trustless Gateway Block Broker
37
+
38
+ The TrustlessGatewayBlockBroker fetches blocks from HTTP gateways.
39
+
40
+ ## Example - Customizing fetch requests with custom headers
41
+
42
+ It is possible to modify outgoing requests to (for example) include
43
+ authentication information (such as a JWT token in a header).
44
+
45
+ ```typescript
46
+ import { createHelia } from 'helia'
47
+ import { trustlessGateway } from '@helia/block-brokers'
48
+ import { unixfs } from '@helia/unixfs'
49
+ import { CID } from 'multiformats/cid'
50
+ import { concat } from 'uint8arrays/concat'
51
+ import all from 'it-all'
52
+
53
+ const helia = await createHelia({
54
+ blockBrokers: [
55
+ trustlessGateway({
56
+ transformRequestInit: (requestInit) => {
57
+ // modify the request init object as required
58
+ requestInit.headers = {
59
+ ...requestInit.headers,
60
+ 'User-Agent': 'Helia Example Script'
61
+ }
62
+ return requestInit
63
+ }
64
+ })
65
+ ]
66
+ })
67
+
68
+ const cid = CID.parse('bafkreife2klsil6kaxqhvmhgldpsvk5yutzm4i5bgjoq6fydefwtihnesa')
69
+ const fs = unixfs(helia)
70
+
71
+ for await (const chunk of fs.cat(cid, {
72
+ signal: AbortSignal.timeout(10_000)
73
+ })) {
74
+ console.info(chunk)
75
+ }
76
+ ```
77
+
16
78
  # Install
17
79
 
18
80
  ```console