@helia/car 5.0.1 → 5.1.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.
Files changed (50) hide show
  1. package/README.md +54 -4
  2. package/dist/index.min.js +1 -1
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/car.d.ts +1 -2
  5. package/dist/src/car.d.ts.map +1 -1
  6. package/dist/src/car.js +46 -124
  7. package/dist/src/car.js.map +1 -1
  8. package/dist/src/errors.d.ts +8 -0
  9. package/dist/src/errors.d.ts.map +1 -1
  10. package/dist/src/errors.js +8 -0
  11. package/dist/src/errors.js.map +1 -1
  12. package/dist/src/export-strategies/block-exporter.d.ts +5 -2
  13. package/dist/src/export-strategies/block-exporter.d.ts.map +1 -1
  14. package/dist/src/export-strategies/block-exporter.js +9 -3
  15. package/dist/src/export-strategies/block-exporter.js.map +1 -1
  16. package/dist/src/export-strategies/subgraph-exporter.d.ts +5 -2
  17. package/dist/src/export-strategies/subgraph-exporter.d.ts.map +1 -1
  18. package/dist/src/export-strategies/subgraph-exporter.js +8 -3
  19. package/dist/src/export-strategies/subgraph-exporter.js.map +1 -1
  20. package/dist/src/export-strategies/unixfs-exporter.d.ts +10 -4
  21. package/dist/src/export-strategies/unixfs-exporter.d.ts.map +1 -1
  22. package/dist/src/export-strategies/unixfs-exporter.js +15 -8
  23. package/dist/src/export-strategies/unixfs-exporter.js.map +1 -1
  24. package/dist/src/index.d.ts +64 -12
  25. package/dist/src/index.d.ts.map +1 -1
  26. package/dist/src/index.js +56 -6
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/src/traversal-strategies/cid-path.d.ts +9 -6
  29. package/dist/src/traversal-strategies/cid-path.d.ts.map +1 -1
  30. package/dist/src/traversal-strategies/cid-path.js +35 -12
  31. package/dist/src/traversal-strategies/cid-path.js.map +1 -1
  32. package/dist/src/traversal-strategies/graph-search.d.ts +15 -7
  33. package/dist/src/traversal-strategies/graph-search.d.ts.map +1 -1
  34. package/dist/src/traversal-strategies/graph-search.js +57 -11
  35. package/dist/src/traversal-strategies/graph-search.js.map +1 -1
  36. package/dist/src/traversal-strategies/unixfs-path.d.ts +53 -3
  37. package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -1
  38. package/dist/src/traversal-strategies/unixfs-path.js +70 -30
  39. package/dist/src/traversal-strategies/unixfs-path.js.map +1 -1
  40. package/dist/typedoc-urls.json +1 -0
  41. package/package.json +4 -2
  42. package/src/car.ts +54 -163
  43. package/src/errors.ts +10 -0
  44. package/src/export-strategies/block-exporter.ts +13 -4
  45. package/src/export-strategies/subgraph-exporter.ts +13 -4
  46. package/src/export-strategies/unixfs-exporter.ts +20 -9
  47. package/src/index.ts +66 -15
  48. package/src/traversal-strategies/cid-path.ts +43 -13
  49. package/src/traversal-strategies/graph-search.ts +70 -12
  50. package/src/traversal-strategies/unixfs-path.ts +77 -41
package/README.md CHANGED
@@ -52,7 +52,9 @@ const cid = CID.parse('QmFoo...')
52
52
  const c = car(helia)
53
53
  const out = nodeFs.createWriteStream('example.car')
54
54
 
55
- for await (const buf of c.export(cid)) {
55
+ for await (const buf of c.export(cid, {
56
+ signal: AbortSignal.timeout(5_000)
57
+ })) {
56
58
  out.write(buf)
57
59
  }
58
60
 
@@ -61,6 +63,14 @@ out.end()
61
63
 
62
64
  ## Example - Exporting a part of a UnixFS DAG as a CAR file
63
65
 
66
+ Here the graph traversal will start at `root` and include the blocks for
67
+ `root`, `/foo`, `/bar`, and all the blocks that make up `baz.txt`.
68
+
69
+ If there are other files/directories in the UnixFS DAG under `root`, they
70
+ will not be included.
71
+
72
+ `root` will be the only entry in the CAR file roots.
73
+
64
74
  ```typescript
65
75
  import { createHelia } from 'helia'
66
76
  import { car, UnixFSPath } from '@helia/car'
@@ -68,12 +78,13 @@ import { CID } from 'multiformats/cid'
68
78
  import nodeFs from 'node:fs'
69
79
 
70
80
  const helia = await createHelia()
71
- const cid = CID.parse('QmFoo...')
81
+ const root = CID.parse('QmFoo...')
72
82
 
73
83
  const c = car(helia)
74
84
  const out = nodeFs.createWriteStream('example.car')
75
85
 
76
- for await (const buf of c.export(cid, {
86
+ for await (const buf of c.export(root, {
87
+ signal: AbortSignal.timeout(5_000),
77
88
  traversal: new UnixFSPath('/foo/bar/baz.txt')
78
89
  })) {
79
90
  out.write(buf)
@@ -82,6 +93,43 @@ for await (const buf of c.export(cid, {
82
93
  out.end()
83
94
  ```
84
95
 
96
+ ## Example - Including traversal path above the root in a CAR
97
+
98
+ The `includeTraversalBlocks` option will include the traversal blocks in the
99
+ CAR when they would otherwise be excluded (for example when the traversal
100
+ starts in a parent of the export root).
101
+
102
+ Here `baz` is the CID for `baz.txt`.
103
+
104
+ The CAR file will include the blocks for `parent`, `/foo`, `/bar`, and
105
+ `/baz.txt`.
106
+
107
+ `baz` will be the only entry in the CAR file roots.
108
+
109
+ ```typescript
110
+ import { createHelia } from 'helia'
111
+ import { car, UnixFSPath } from '@helia/car'
112
+ import { CID } from 'multiformats/cid'
113
+ import nodeFs from 'node:fs'
114
+
115
+ const helia = await createHelia()
116
+ const parent = CID.parse('QmFoo...')
117
+ const baz = CID.parse('QmBar...')
118
+
119
+ const c = car(helia)
120
+ const out = nodeFs.createWriteStream('example.car')
121
+
122
+ for await (const buf of c.export(baz, {
123
+ signal: AbortSignal.timeout(5_000),
124
+ traversal: new UnixFSPath(parent, '/foo/bar/baz.txt'),
125
+ includeTraversalBlocks: true
126
+ })) {
127
+ out.write(buf)
128
+ }
129
+
130
+ out.end()
131
+ ```
132
+
85
133
  ## Example - Importing all blocks from a CAR file
86
134
 
87
135
  ```typescript
@@ -101,7 +149,9 @@ const inStream = nodeFs.createReadStream('example.car')
101
149
  const reader = await CarReader.fromIterable(inStream)
102
150
 
103
151
  const c = car(helia)
104
- await c.import(reader)
152
+ await c.import(reader, {
153
+ signal: AbortSignal.timeout(5_000)
154
+ })
105
155
  ```
106
156
 
107
157
  # Install