+56
packages/utilities/car/README.md
+56
packages/utilities/car/README.md
···
5
5
6
6
[dasl-car]: https://dasl.ing/car.html
7
7
8
+
## usage
9
+
10
+
### streaming usage
11
+
8
12
```ts
9
13
import { CarReader, RepoReader } from '@atcute/car/v4';
14
+
15
+
const stream = new ReadableStream({
16
+
/* ... */
17
+
});
10
18
11
19
// read AT Protocol repository exports
12
20
{
···
33
41
}
34
42
}
35
43
```
44
+
45
+
### streaming usage (for runtimes without `await using` yet)
46
+
47
+
```ts
48
+
const repo = RepoReader.fromStream(stream);
49
+
50
+
try {
51
+
for await (const entry of repo) {
52
+
entry;
53
+
// ^? RepoEntry
54
+
}
55
+
} finally {
56
+
await repo.dispose();
57
+
}
58
+
```
59
+
60
+
### sync usage
61
+
62
+
```ts
63
+
const buffer = Uint8Array.from([
64
+
/* ... */
65
+
]);
66
+
67
+
// read AT Protocol repository exports
68
+
{
69
+
const repo = RepoReader.fromUint8Array(buffer);
70
+
71
+
for (const entry of repo) {
72
+
entry;
73
+
// ^? RepoEntry { collection: 'app.bsky.feed.post', rkey: '3lprcc55bb222', ... }
74
+
}
75
+
76
+
repo.missingBlocks;
77
+
// ^? []
78
+
}
79
+
80
+
// read generic CAR archives
81
+
{
82
+
const car = CarReader.fromUint8Array(buffer);
83
+
84
+
const roots = car.roots;
85
+
86
+
for (const entry of car) {
87
+
entry;
88
+
// ^? CarEntry { cid: CidLink {}, bytes: Uint8Array {}, ... }
89
+
}
90
+
}
91
+
```