@helia/car 4.2.0-34d3ecd7 → 4.2.0-93aa4645
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 +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/car.d.ts +2 -3
- package/dist/src/car.d.ts.map +1 -1
- package/dist/src/car.js +38 -22
- package/dist/src/car.js.map +1 -1
- package/dist/src/index.d.ts +5 -36
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/package.json +6 -7
- package/src/car.ts +45 -26
- package/src/index.ts +5 -37
package/dist/src/car.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CarWriter } from '@ipld/car';
|
|
2
1
|
import type { CarComponents, Car as CarInterface, ExportCarOptions } from './index.js';
|
|
3
2
|
import type { PutManyBlocksProgressEvents } from '@helia/interface/blocks';
|
|
4
3
|
import type { CarReader } from '@ipld/car';
|
|
@@ -11,7 +10,7 @@ export declare class Car implements CarInterface {
|
|
|
11
10
|
private readonly log;
|
|
12
11
|
constructor(components: CarComponents, init: any);
|
|
13
12
|
import(reader: Pick<CarReader, 'blocks'>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): Promise<void>;
|
|
14
|
-
export(root: CID | CID[],
|
|
15
|
-
|
|
13
|
+
export(root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined>;
|
|
14
|
+
private _export;
|
|
16
15
|
}
|
|
17
16
|
//# sourceMappingURL=car.d.ts.map
|
package/dist/src/car.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,YAAY,EAAE,gBAAgB,EAAqC,MAAM,YAAY,CAAA;AACzH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,mBAAmB,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AA2BtD,qBAAa,GAAI,YAAW,YAAY;;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG;IAK3C,MAAM,CAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9H,MAAM,CAAE,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;YAkC7F,OAAO;CAiJtB"}
|
package/dist/src/car.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CarWriter } from '@ipld/car';
|
|
2
|
+
import { Queue } from '@libp2p/utils';
|
|
2
3
|
import drain from 'it-drain';
|
|
3
4
|
import map from 'it-map';
|
|
4
5
|
import toBuffer from 'it-to-buffer';
|
|
5
6
|
import { createUnsafe } from 'multiformats/block';
|
|
6
|
-
import
|
|
7
|
-
import PQueue from 'p-queue';
|
|
7
|
+
import { raceSignal } from 'race-signal';
|
|
8
8
|
import { DAG_WALK_QUEUE_CONCURRENCY } from './constants.js';
|
|
9
9
|
import { SubgraphExporter } from './export-strategies/subgraph-exporter.js';
|
|
10
10
|
import { GraphSearch } from './traversal-strategies/graph-search.js';
|
|
@@ -18,8 +18,36 @@ export class Car {
|
|
|
18
18
|
async import(reader, options) {
|
|
19
19
|
await drain(this.components.blockstore.putMany(map(reader.blocks(), ({ cid, bytes }) => ({ cid, bytes })), options));
|
|
20
20
|
}
|
|
21
|
-
async export(root,
|
|
22
|
-
const
|
|
21
|
+
async *export(root, options) {
|
|
22
|
+
const { writer, out } = CarWriter.create(root);
|
|
23
|
+
const iter = out[Symbol.asyncIterator]();
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
// has to be done async so we write to `writer` and read from `out` at the
|
|
26
|
+
// same time
|
|
27
|
+
this._export(root, writer, options)
|
|
28
|
+
.catch((err) => {
|
|
29
|
+
this.log.error('error during streaming export - %e', err);
|
|
30
|
+
controller.abort(err);
|
|
31
|
+
});
|
|
32
|
+
while (true) {
|
|
33
|
+
const { done, value } = await raceSignal(iter.next(), controller.signal);
|
|
34
|
+
// the writer's `out` iterable can yield results synchronously, in which
|
|
35
|
+
// case the controller may have been aborted but the event may not have
|
|
36
|
+
// fired yet so check the signal status manually before processing the
|
|
37
|
+
// next iterable result
|
|
38
|
+
if (controller.signal.aborted) {
|
|
39
|
+
throw controller.signal.reason;
|
|
40
|
+
}
|
|
41
|
+
if (value != null) {
|
|
42
|
+
yield value;
|
|
43
|
+
}
|
|
44
|
+
if (done === true) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async _export(root, writer, options) {
|
|
50
|
+
const deferred = Promise.withResolvers();
|
|
23
51
|
const roots = Array.isArray(root) ? root : [root];
|
|
24
52
|
// Create traversal-specific context
|
|
25
53
|
const traversalContext = {
|
|
@@ -30,11 +58,11 @@ export class Car {
|
|
|
30
58
|
const exportStrategy = options?.exporter ?? new SubgraphExporter();
|
|
31
59
|
// use a queue to walk the DAG instead of recursion so we can traverse very
|
|
32
60
|
// large DAGs
|
|
33
|
-
const queue = new
|
|
61
|
+
const queue = new Queue({
|
|
34
62
|
concurrency: DAG_WALK_QUEUE_CONCURRENCY
|
|
35
63
|
});
|
|
36
64
|
let startedExport = false;
|
|
37
|
-
queue.
|
|
65
|
+
queue.addEventListener('idle', () => {
|
|
38
66
|
if (startedExport) {
|
|
39
67
|
// idle event was called, and started exporting, so we are done.
|
|
40
68
|
deferred.resolve();
|
|
@@ -49,7 +77,7 @@ export class Car {
|
|
|
49
77
|
const targetCid = path[targetIndex];
|
|
50
78
|
// Process all verification blocks in the path except the target
|
|
51
79
|
path.slice(0, -1).forEach(cid => {
|
|
52
|
-
|
|
80
|
+
queue.add(async () => {
|
|
53
81
|
await this.#exportDagNode({ cid, queue, writer, strategy: exportStrategy, options, recursive: false });
|
|
54
82
|
})
|
|
55
83
|
.catch((err) => {
|
|
@@ -57,7 +85,7 @@ export class Car {
|
|
|
57
85
|
});
|
|
58
86
|
});
|
|
59
87
|
// Process the target block (which will recursively export its DAG)
|
|
60
|
-
|
|
88
|
+
queue.add(async () => {
|
|
61
89
|
await this.#exportDagNode({ cid: targetCid, queue, writer, strategy: exportStrategy, options });
|
|
62
90
|
})
|
|
63
91
|
.catch((err) => {
|
|
@@ -74,9 +102,9 @@ export class Car {
|
|
|
74
102
|
deferred.reject(new Error('Could not traverse to target CID(s)'));
|
|
75
103
|
}
|
|
76
104
|
});
|
|
77
|
-
queue.
|
|
105
|
+
queue.addEventListener('failure', (evt) => {
|
|
78
106
|
queue.clear();
|
|
79
|
-
deferred.reject(
|
|
107
|
+
deferred.reject(evt.detail.error);
|
|
80
108
|
});
|
|
81
109
|
for (const root of roots) {
|
|
82
110
|
void queue.add(async () => {
|
|
@@ -95,18 +123,6 @@ export class Car {
|
|
|
95
123
|
await writer.close();
|
|
96
124
|
}
|
|
97
125
|
}
|
|
98
|
-
async *stream(root, options) {
|
|
99
|
-
const { writer, out } = CarWriter.create(root);
|
|
100
|
-
// has to be done async so we write to `writer` and read from `out` at the
|
|
101
|
-
// same time
|
|
102
|
-
this.export(root, writer, options)
|
|
103
|
-
.catch((err) => {
|
|
104
|
-
this.log.error('error during streaming export - %e', err);
|
|
105
|
-
});
|
|
106
|
-
for await (const buf of out) {
|
|
107
|
-
yield buf;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
126
|
/**
|
|
111
127
|
* Traverse a DAG and stop when we reach the target node
|
|
112
128
|
*/
|
package/dist/src/car.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"car.js","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"car.js","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAA;AAiCpE,MAAM,OAAO,GAAG;IACG,UAAU,CAAe;IACzB,GAAG,CAAQ;IAE5B,YAAa,UAAyB,EAAE,IAAS;QAC/C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H,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* const c = car(helia)
|
|
24
24
|
* const out = nodeFs.createWriteStream('example.car')
|
|
25
25
|
*
|
|
26
|
-
* for await (const buf of c.
|
|
26
|
+
* for await (const buf of c.export(cid)) {
|
|
27
27
|
* out.write(buf)
|
|
28
28
|
* }
|
|
29
29
|
*
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
* const c = car(helia)
|
|
45
45
|
* const out = nodeFs.createWriteStream('example.car')
|
|
46
46
|
*
|
|
47
|
-
* for await (const buf of c.
|
|
47
|
+
* for await (const buf of c.export(cid, {
|
|
48
48
|
* traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
49
49
|
* })) {
|
|
50
50
|
* out.write(buf)
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
*/
|
|
78
78
|
import type { CodecLoader } from '@helia/interface';
|
|
79
79
|
import type { PutManyBlocksProgressEvents, GetBlockProgressEvents, ProviderOptions } from '@helia/interface/blocks';
|
|
80
|
-
import type {
|
|
80
|
+
import type { CarReader } from '@ipld/car';
|
|
81
81
|
import type { AbortOptions, ComponentLogger } from '@libp2p/interface';
|
|
82
82
|
import type { Filter } from '@libp2p/utils';
|
|
83
83
|
import type { Blockstore } from 'interface-blockstore';
|
|
@@ -168,37 +168,6 @@ export interface Car {
|
|
|
168
168
|
* ```
|
|
169
169
|
*/
|
|
170
170
|
import(reader: Pick<CarReader, 'blocks'>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): Promise<void>;
|
|
171
|
-
/**
|
|
172
|
-
* Store all blocks that make up one or more DAGs in a car file.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
*
|
|
176
|
-
* ```typescript
|
|
177
|
-
* import fs from 'node:fs'
|
|
178
|
-
* import { Readable } from 'node:stream'
|
|
179
|
-
* import { car } from '@helia/car'
|
|
180
|
-
* import { CarWriter } from '@ipld/car'
|
|
181
|
-
* import { createHelia } from 'helia'
|
|
182
|
-
* import { CID } from 'multiformats/cid'
|
|
183
|
-
* import { pEvent } from 'p-event'
|
|
184
|
-
*
|
|
185
|
-
* const helia = await createHelia()
|
|
186
|
-
* const cid = CID.parse('QmFoo...')
|
|
187
|
-
*
|
|
188
|
-
* const c = car(helia)
|
|
189
|
-
* const { writer, out } = CarWriter.create(cid)
|
|
190
|
-
* const output = fs.createWriteStream('example.car')
|
|
191
|
-
* const stream = Readable.from(out).pipe(output)
|
|
192
|
-
*
|
|
193
|
-
* await Promise.all([
|
|
194
|
-
* c.export(cid, writer),
|
|
195
|
-
* pEvent(stream, 'close')
|
|
196
|
-
* ])
|
|
197
|
-
* ```
|
|
198
|
-
*
|
|
199
|
-
* @deprecated Use `stream` instead. In a future release `stream` will be renamed `export`.
|
|
200
|
-
*/
|
|
201
|
-
export(root: CID | CID[], writer: Pick<CarWriter, 'put' | 'close'>, options?: ExportCarOptions): Promise<void>;
|
|
202
171
|
/**
|
|
203
172
|
* Returns an AsyncGenerator that yields CAR file bytes.
|
|
204
173
|
*
|
|
@@ -214,12 +183,12 @@ export interface Car {
|
|
|
214
183
|
*
|
|
215
184
|
* const c = car(helia)
|
|
216
185
|
*
|
|
217
|
-
* for (const buf of c.
|
|
186
|
+
* for (const buf of c.export(cid)) {
|
|
218
187
|
* // store or send `buf` somewhere
|
|
219
188
|
* }
|
|
220
189
|
* ```
|
|
221
190
|
*/
|
|
222
|
-
|
|
191
|
+
export(root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined>;
|
|
223
192
|
}
|
|
224
193
|
/**
|
|
225
194
|
* Create a {@link Car} instance for use with {@link https://github.com/ipfs/helia Helia}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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nG;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAE,KAAK,EAAE,aAAa,EAAE,IAAI,GAAE,GAAQ,GAAG,GAAG,CAE9D"}
|
package/dist/src/index.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* const c = car(helia)
|
|
24
24
|
* const out = nodeFs.createWriteStream('example.car')
|
|
25
25
|
*
|
|
26
|
-
* for await (const buf of c.
|
|
26
|
+
* for await (const buf of c.export(cid)) {
|
|
27
27
|
* out.write(buf)
|
|
28
28
|
* }
|
|
29
29
|
*
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
* const c = car(helia)
|
|
45
45
|
* const out = nodeFs.createWriteStream('example.car')
|
|
46
46
|
*
|
|
47
|
-
* for await (const buf of c.
|
|
47
|
+
* for await (const buf of c.export(cid, {
|
|
48
48
|
* traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
49
49
|
* })) {
|
|
50
50
|
* out.write(buf)
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAgD1C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAgD1C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iCAAiC,CAAA;AAgF/C;;GAEG;AACH,MAAM,UAAU,GAAG,CAAE,KAAoB,EAAE,OAAY,EAAE;IACvD,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/car",
|
|
3
|
-
"version": "4.2.0-
|
|
3
|
+
"version": "4.2.0-93aa4645",
|
|
4
4
|
"description": "Import/export car files from Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/car#readme",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"test:electron-main": "aegir test -t electron-main"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@helia/interface": "5.4.0-
|
|
50
|
+
"@helia/interface": "5.4.0-93aa4645",
|
|
51
51
|
"@ipld/car": "^5.4.2",
|
|
52
52
|
"@ipld/dag-pb": "^4.1.5",
|
|
53
53
|
"@libp2p/interface": "^3.0.2",
|
|
@@ -58,13 +58,12 @@
|
|
|
58
58
|
"it-map": "^3.1.4",
|
|
59
59
|
"it-to-buffer": "^4.0.10",
|
|
60
60
|
"multiformats": "^13.4.1",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"progress-events": "^1.0.1"
|
|
61
|
+
"progress-events": "^1.0.1",
|
|
62
|
+
"race-signal": "^2.0.0"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
|
-
"@helia/mfs": "5.1.0-
|
|
67
|
-
"@helia/unixfs": "5.1.0-
|
|
65
|
+
"@helia/mfs": "5.1.0-93aa4645",
|
|
66
|
+
"@helia/unixfs": "5.1.0-93aa4645",
|
|
68
67
|
"@ipld/dag-cbor": "^9.2.5",
|
|
69
68
|
"@libp2p/logger": "^6.0.5",
|
|
70
69
|
"aegir": "^47.0.22",
|
package/src/car.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CarWriter } from '@ipld/car'
|
|
2
|
+
import { Queue } from '@libp2p/utils'
|
|
2
3
|
import drain from 'it-drain'
|
|
3
4
|
import map from 'it-map'
|
|
4
5
|
import toBuffer from 'it-to-buffer'
|
|
5
6
|
import { createUnsafe } from 'multiformats/block'
|
|
6
|
-
import
|
|
7
|
-
import PQueue from 'p-queue'
|
|
7
|
+
import { raceSignal } from 'race-signal'
|
|
8
8
|
import { DAG_WALK_QUEUE_CONCURRENCY } from './constants.js'
|
|
9
9
|
import { SubgraphExporter } from './export-strategies/subgraph-exporter.js'
|
|
10
10
|
import { GraphSearch } from './traversal-strategies/graph-search.js'
|
|
@@ -25,7 +25,7 @@ interface TraversalContext {
|
|
|
25
25
|
|
|
26
26
|
interface WalkDagContext<Strategy> {
|
|
27
27
|
cid: CID
|
|
28
|
-
queue:
|
|
28
|
+
queue: Queue
|
|
29
29
|
strategy: Strategy
|
|
30
30
|
options?: ExportCarOptions
|
|
31
31
|
}
|
|
@@ -56,8 +56,42 @@ export class Car implements CarInterface {
|
|
|
56
56
|
))
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
async export (root: CID | CID[],
|
|
60
|
-
const
|
|
59
|
+
async * export (root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined> {
|
|
60
|
+
const { writer, out } = CarWriter.create(root)
|
|
61
|
+
const iter = out[Symbol.asyncIterator]()
|
|
62
|
+
const controller = new AbortController()
|
|
63
|
+
|
|
64
|
+
// has to be done async so we write to `writer` and read from `out` at the
|
|
65
|
+
// same time
|
|
66
|
+
this._export(root, writer, options)
|
|
67
|
+
.catch((err) => {
|
|
68
|
+
this.log.error('error during streaming export - %e', err)
|
|
69
|
+
controller.abort(err)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
while (true) {
|
|
73
|
+
const { done, value } = await raceSignal(iter.next(), controller.signal)
|
|
74
|
+
|
|
75
|
+
// the writer's `out` iterable can yield results synchronously, in which
|
|
76
|
+
// case the controller may have been aborted but the event may not have
|
|
77
|
+
// fired yet so check the signal status manually before processing the
|
|
78
|
+
// next iterable result
|
|
79
|
+
if (controller.signal.aborted) {
|
|
80
|
+
throw controller.signal.reason
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (value != null) {
|
|
84
|
+
yield value
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (done === true) {
|
|
88
|
+
break
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private async _export (root: CID | CID[], writer: Pick<CarWriter, 'put' | 'close'>, options?: ExportCarOptions): Promise<void> {
|
|
94
|
+
const deferred = Promise.withResolvers<Error | void>()
|
|
61
95
|
const roots = Array.isArray(root) ? root : [root]
|
|
62
96
|
|
|
63
97
|
// Create traversal-specific context
|
|
@@ -71,12 +105,12 @@ export class Car implements CarInterface {
|
|
|
71
105
|
|
|
72
106
|
// use a queue to walk the DAG instead of recursion so we can traverse very
|
|
73
107
|
// large DAGs
|
|
74
|
-
const queue = new
|
|
108
|
+
const queue = new Queue({
|
|
75
109
|
concurrency: DAG_WALK_QUEUE_CONCURRENCY
|
|
76
110
|
})
|
|
77
111
|
|
|
78
112
|
let startedExport = false
|
|
79
|
-
queue.
|
|
113
|
+
queue.addEventListener('idle', () => {
|
|
80
114
|
if (startedExport) {
|
|
81
115
|
// idle event was called, and started exporting, so we are done.
|
|
82
116
|
deferred.resolve()
|
|
@@ -92,7 +126,7 @@ export class Car implements CarInterface {
|
|
|
92
126
|
|
|
93
127
|
// Process all verification blocks in the path except the target
|
|
94
128
|
path.slice(0, -1).forEach(cid => {
|
|
95
|
-
|
|
129
|
+
queue.add(async () => {
|
|
96
130
|
await this.#exportDagNode({ cid, queue, writer, strategy: exportStrategy, options, recursive: false })
|
|
97
131
|
})
|
|
98
132
|
.catch((err) => {
|
|
@@ -101,7 +135,7 @@ export class Car implements CarInterface {
|
|
|
101
135
|
})
|
|
102
136
|
|
|
103
137
|
// Process the target block (which will recursively export its DAG)
|
|
104
|
-
|
|
138
|
+
queue.add(async () => {
|
|
105
139
|
await this.#exportDagNode({ cid: targetCid, queue, writer, strategy: exportStrategy, options })
|
|
106
140
|
})
|
|
107
141
|
.catch((err) => {
|
|
@@ -117,9 +151,9 @@ export class Car implements CarInterface {
|
|
|
117
151
|
deferred.reject(new Error('Could not traverse to target CID(s)'))
|
|
118
152
|
}
|
|
119
153
|
})
|
|
120
|
-
queue.
|
|
154
|
+
queue.addEventListener('failure', (evt) => {
|
|
121
155
|
queue.clear()
|
|
122
|
-
deferred.reject(
|
|
156
|
+
deferred.reject(evt.detail.error)
|
|
123
157
|
})
|
|
124
158
|
|
|
125
159
|
for (const root of roots) {
|
|
@@ -140,21 +174,6 @@ export class Car implements CarInterface {
|
|
|
140
174
|
}
|
|
141
175
|
}
|
|
142
176
|
|
|
143
|
-
async * stream (root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined> {
|
|
144
|
-
const { writer, out } = CarWriter.create(root)
|
|
145
|
-
|
|
146
|
-
// has to be done async so we write to `writer` and read from `out` at the
|
|
147
|
-
// same time
|
|
148
|
-
this.export(root, writer, options)
|
|
149
|
-
.catch((err) => {
|
|
150
|
-
this.log.error('error during streaming export - %e', err)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
for await (const buf of out) {
|
|
154
|
-
yield buf
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
177
|
/**
|
|
159
178
|
* Traverse a DAG and stop when we reach the target node
|
|
160
179
|
*/
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* const c = car(helia)
|
|
24
24
|
* const out = nodeFs.createWriteStream('example.car')
|
|
25
25
|
*
|
|
26
|
-
* for await (const buf of c.
|
|
26
|
+
* for await (const buf of c.export(cid)) {
|
|
27
27
|
* out.write(buf)
|
|
28
28
|
* }
|
|
29
29
|
*
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
* const c = car(helia)
|
|
45
45
|
* const out = nodeFs.createWriteStream('example.car')
|
|
46
46
|
*
|
|
47
|
-
* for await (const buf of c.
|
|
47
|
+
* for await (const buf of c.export(cid, {
|
|
48
48
|
* traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
49
49
|
* })) {
|
|
50
50
|
* out.write(buf)
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
import { Car as CarClass } from './car.js'
|
|
80
80
|
import type { CodecLoader } from '@helia/interface'
|
|
81
81
|
import type { PutManyBlocksProgressEvents, GetBlockProgressEvents, ProviderOptions } from '@helia/interface/blocks'
|
|
82
|
-
import type {
|
|
82
|
+
import type { CarReader } from '@ipld/car'
|
|
83
83
|
import type { AbortOptions, ComponentLogger } from '@libp2p/interface'
|
|
84
84
|
import type { Filter } from '@libp2p/utils'
|
|
85
85
|
import type { Blockstore } from 'interface-blockstore'
|
|
@@ -182,38 +182,6 @@ export interface Car {
|
|
|
182
182
|
*/
|
|
183
183
|
import(reader: Pick<CarReader, 'blocks'>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): Promise<void>
|
|
184
184
|
|
|
185
|
-
/**
|
|
186
|
-
* Store all blocks that make up one or more DAGs in a car file.
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
*
|
|
190
|
-
* ```typescript
|
|
191
|
-
* import fs from 'node:fs'
|
|
192
|
-
* import { Readable } from 'node:stream'
|
|
193
|
-
* import { car } from '@helia/car'
|
|
194
|
-
* import { CarWriter } from '@ipld/car'
|
|
195
|
-
* import { createHelia } from 'helia'
|
|
196
|
-
* import { CID } from 'multiformats/cid'
|
|
197
|
-
* import { pEvent } from 'p-event'
|
|
198
|
-
*
|
|
199
|
-
* const helia = await createHelia()
|
|
200
|
-
* const cid = CID.parse('QmFoo...')
|
|
201
|
-
*
|
|
202
|
-
* const c = car(helia)
|
|
203
|
-
* const { writer, out } = CarWriter.create(cid)
|
|
204
|
-
* const output = fs.createWriteStream('example.car')
|
|
205
|
-
* const stream = Readable.from(out).pipe(output)
|
|
206
|
-
*
|
|
207
|
-
* await Promise.all([
|
|
208
|
-
* c.export(cid, writer),
|
|
209
|
-
* pEvent(stream, 'close')
|
|
210
|
-
* ])
|
|
211
|
-
* ```
|
|
212
|
-
*
|
|
213
|
-
* @deprecated Use `stream` instead. In a future release `stream` will be renamed `export`.
|
|
214
|
-
*/
|
|
215
|
-
export(root: CID | CID[], writer: Pick<CarWriter, 'put' | 'close'>, options?: ExportCarOptions): Promise<void>
|
|
216
|
-
|
|
217
185
|
/**
|
|
218
186
|
* Returns an AsyncGenerator that yields CAR file bytes.
|
|
219
187
|
*
|
|
@@ -229,12 +197,12 @@ export interface Car {
|
|
|
229
197
|
*
|
|
230
198
|
* const c = car(helia)
|
|
231
199
|
*
|
|
232
|
-
* for (const buf of c.
|
|
200
|
+
* for (const buf of c.export(cid)) {
|
|
233
201
|
* // store or send `buf` somewhere
|
|
234
202
|
* }
|
|
235
203
|
* ```
|
|
236
204
|
*/
|
|
237
|
-
|
|
205
|
+
export(root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined>
|
|
238
206
|
}
|
|
239
207
|
|
|
240
208
|
/**
|