@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.
- package/README.md +54 -4
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/car.d.ts +1 -2
- package/dist/src/car.d.ts.map +1 -1
- package/dist/src/car.js +46 -124
- package/dist/src/car.js.map +1 -1
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +8 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/export-strategies/block-exporter.d.ts +5 -2
- package/dist/src/export-strategies/block-exporter.d.ts.map +1 -1
- package/dist/src/export-strategies/block-exporter.js +9 -3
- package/dist/src/export-strategies/block-exporter.js.map +1 -1
- package/dist/src/export-strategies/subgraph-exporter.d.ts +5 -2
- package/dist/src/export-strategies/subgraph-exporter.d.ts.map +1 -1
- package/dist/src/export-strategies/subgraph-exporter.js +8 -3
- package/dist/src/export-strategies/subgraph-exporter.js.map +1 -1
- package/dist/src/export-strategies/unixfs-exporter.d.ts +10 -4
- package/dist/src/export-strategies/unixfs-exporter.d.ts.map +1 -1
- package/dist/src/export-strategies/unixfs-exporter.js +15 -8
- package/dist/src/export-strategies/unixfs-exporter.js.map +1 -1
- package/dist/src/index.d.ts +64 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +56 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/traversal-strategies/cid-path.d.ts +9 -6
- package/dist/src/traversal-strategies/cid-path.d.ts.map +1 -1
- package/dist/src/traversal-strategies/cid-path.js +35 -12
- package/dist/src/traversal-strategies/cid-path.js.map +1 -1
- package/dist/src/traversal-strategies/graph-search.d.ts +15 -7
- package/dist/src/traversal-strategies/graph-search.d.ts.map +1 -1
- package/dist/src/traversal-strategies/graph-search.js +57 -11
- package/dist/src/traversal-strategies/graph-search.js.map +1 -1
- package/dist/src/traversal-strategies/unixfs-path.d.ts +53 -3
- package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -1
- package/dist/src/traversal-strategies/unixfs-path.js +70 -30
- package/dist/src/traversal-strategies/unixfs-path.js.map +1 -1
- package/dist/typedoc-urls.json +1 -0
- package/package.json +4 -2
- package/src/car.ts +54 -163
- package/src/errors.ts +10 -0
- package/src/export-strategies/block-exporter.ts +13 -4
- package/src/export-strategies/subgraph-exporter.ts +13 -4
- package/src/export-strategies/unixfs-exporter.ts +20 -9
- package/src/index.ts +66 -15
- package/src/traversal-strategies/cid-path.ts +43 -13
- package/src/traversal-strategies/graph-search.ts +70 -12
- 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
|
|
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(
|
|
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
|