@atcute/car 3.1.0 → 3.1.2

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 (36) hide show
  1. package/LICENSE +12 -15
  2. package/README.md +56 -0
  3. package/dist/v3/atproto-repo.d.ts +1 -0
  4. package/dist/v3/atproto-repo.d.ts.map +1 -0
  5. package/dist/v3/index.d.ts +1 -0
  6. package/dist/v3/index.d.ts.map +1 -0
  7. package/dist/v3/reader.d.ts +1 -0
  8. package/dist/v3/reader.d.ts.map +1 -0
  9. package/dist/v4/car-reader/index.d.ts +1 -0
  10. package/dist/v4/car-reader/index.d.ts.map +1 -0
  11. package/dist/v4/car-reader/stream-car-reader.d.ts +1 -0
  12. package/dist/v4/car-reader/stream-car-reader.d.ts.map +1 -0
  13. package/dist/v4/car-reader/sync-car-reader.d.ts +1 -0
  14. package/dist/v4/car-reader/sync-car-reader.d.ts.map +1 -0
  15. package/dist/v4/car-reader/types.d.ts +1 -0
  16. package/dist/v4/car-reader/types.d.ts.map +1 -0
  17. package/dist/v4/index.d.ts +1 -0
  18. package/dist/v4/index.d.ts.map +1 -0
  19. package/dist/v4/repo-reader/index.d.ts +1 -0
  20. package/dist/v4/repo-reader/index.d.ts.map +1 -0
  21. package/dist/v4/repo-reader/mst.d.ts +1 -0
  22. package/dist/v4/repo-reader/mst.d.ts.map +1 -0
  23. package/dist/v4/repo-reader/stream-repo-reader.d.ts +1 -0
  24. package/dist/v4/repo-reader/stream-repo-reader.d.ts.map +1 -0
  25. package/dist/v4/repo-reader/stream-repo-reader.js +77 -71
  26. package/dist/v4/repo-reader/stream-repo-reader.js.map +1 -1
  27. package/dist/v4/repo-reader/sync-blockmap.d.ts +1 -0
  28. package/dist/v4/repo-reader/sync-blockmap.d.ts.map +1 -0
  29. package/dist/v4/repo-reader/sync-repo-reader.d.ts +1 -0
  30. package/dist/v4/repo-reader/sync-repo-reader.d.ts.map +1 -0
  31. package/dist/v4/repo-reader/types.d.ts +1 -0
  32. package/dist/v4/repo-reader/types.d.ts.map +1 -0
  33. package/dist/v4/utils.d.ts +1 -0
  34. package/dist/v4/utils.d.ts.map +1 -0
  35. package/lib/v4/repo-reader/stream-repo-reader.ts +82 -77
  36. package/package.json +8 -8
package/LICENSE CHANGED
@@ -1,17 +1,14 @@
1
- Permission is hereby granted, free of charge, to any person obtaining a copy
2
- of this software and associated documentation files (the "Software"), to deal
3
- in the Software without restriction, including without limitation the rights
4
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5
- copies of the Software, and to permit persons to whom the Software is
6
- furnished to do so, subject to the following conditions:
1
+ BSD Zero Clause License
7
2
 
8
- The above copyright notice and this permission notice shall be included in all
9
- copies or substantial portions of the Software.
3
+ Copyright (c) 2025 Mary
10
4
 
11
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
- SOFTWARE.
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -5,9 +5,17 @@ library for AT Protocol.
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';
10
14
 
15
+ const stream = new ReadableStream({
16
+ /* ... */
17
+ });
18
+
11
19
  // read AT Protocol repository exports
12
20
  {
13
21
  await using repo = RepoReader.fromStream(stream);
@@ -33,3 +41,51 @@ import { CarReader, RepoReader } from '@atcute/car/v4';
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
+ ```
@@ -1 +1,2 @@
1
1
  export { collectBlock, isCommit, isMstNode, isTreeEntry, fromUint8Array as iterateAtpRepo, readBlock, RepoEntry, walkMstEntries, type BlockMap, type Commit, type MstNode, type NodeEntry, type TreeEntry, } from '../v4/repo-reader/index.js';
2
+ //# sourceMappingURL=atproto-repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atproto-repo.d.ts","sourceRoot":"","sources":["../../lib/v3/atproto-repo.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,cAAc,IAAI,cAAc,EAChC,SAAS,EACT,SAAS,EACT,cAAc,EACd,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,GACd,MAAM,4BAA4B,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from './atproto-repo.js';
2
2
  export * from './reader.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
@@ -1 +1,2 @@
1
1
  export { isCarV1Header, fromUint8Array as readCar, type CarEntry, type CarHeader, type CarV1Header, type StreamedCarReader, type SyncCarReader, } from '../v4/car-reader/index.js';
2
+ //# sourceMappingURL=reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../lib/v3/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,cAAc,IAAI,OAAO,EACzB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GAClB,MAAM,2BAA2B,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from './types.js';
2
2
  export * from './stream-car-reader.js';
3
3
  export * from './sync-car-reader.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v4/car-reader/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
@@ -9,3 +9,4 @@ export interface StreamedCarReader {
9
9
  }
10
10
  export declare const carEntryTransform: () => ReadableWritablePair<CarEntry, Uint8Array>;
11
11
  export declare const fromStream: (stream: ReadableStream<Uint8Array>) => StreamedCarReader;
12
+ //# sourceMappingURL=stream-car-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-car-reader.d.ts","sourceRoot":"","sources":["../../../lib/v4/car-reader/stream-car-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AAIrC,OAAO,EAAiB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,WAAW,iBAAiB;IACjC,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAEjC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClD;AAED,eAAO,MAAM,iBAAiB,QAAO,oBAAoB,CAAC,QAAQ,EAAE,UAAU,CA6B7E,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,cAAc,CAAC,UAAU,CAAC,KAAG,iBAgM/D,CAAC"}
@@ -8,3 +8,4 @@ export interface SyncCarReader {
8
8
  [Symbol.iterator](): Iterator<CarEntry>;
9
9
  }
10
10
  export declare const fromUint8Array: (buffer: Uint8Array) => SyncCarReader;
11
+ //# sourceMappingURL=sync-car-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-car-reader.d.ts","sourceRoot":"","sources":["../../../lib/v4/car-reader/sync-car-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AAIrC,OAAO,EAAiB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAS1E,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IAE/B,oDAAoD;IACpD,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,cAAc,GAAI,QAAQ,UAAU,KAAG,aA0CnD,CAAC"}
@@ -21,3 +21,4 @@ export interface CarEntry {
21
21
  bytesStart: number;
22
22
  bytesEnd: number;
23
23
  }
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/v4/car-reader/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAOvD,CAAC;AAEF,MAAM,WAAW,SAAS;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IAEjB,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IAEf,KAAK,EAAE,UAAU,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB"}
@@ -1,2 +1,3 @@
1
1
  export * as CarReader from './car-reader/index.js';
2
2
  export * as RepoReader from './repo-reader/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/v4/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC"}
@@ -3,3 +3,4 @@ export * from './mst.js';
3
3
  export * from './stream-repo-reader.js';
4
4
  export * from './sync-blockmap.js';
5
5
  export * from './sync-repo-reader.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v4/repo-reader/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
@@ -45,3 +45,4 @@ export interface MstNode {
45
45
  * @returns true if the value is a valid mst node object, false otherwise
46
46
  */
47
47
  export declare const isMstNode: (value: unknown) => value is MstNode;
48
+ //# sourceMappingURL=mst.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mst.d.ts","sourceRoot":"","sources":["../../../lib/v4/repo-reader/mst.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AA0BnC,oBAAoB;AACpB,MAAM,WAAW,MAAM;IACtB,OAAO,EAAE,CAAC,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC;CAChB;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAelD,CAAC;AAEF,4BAA4B;AAC5B,MAAM,WAAW,SAAS;IACzB,0EAA0E;IAC1E,CAAC,EAAE,MAAM,CAAC;IACV,+EAA+E;IAC/E,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;IACd,6KAA6K;IAC7K,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACf,0CAA0C;IAC1C,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAUrD,CAAC;AAEF,sBAAsB;AACtB,MAAM,WAAW,OAAO;IACvB,gGAAgG;IAChG,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,wCAAwC;IACxC,CAAC,EAAE,SAAS,EAAE,CAAC;CACf;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAQnD,CAAC"}
@@ -22,3 +22,4 @@ export interface StreamedRepoReader {
22
22
  }
23
23
  export declare const repoEntryTransform: () => ReadableWritablePair<RepoEntry, Uint8Array>;
24
24
  export declare const fromStream: (stream: ReadableStream<Uint8Array>) => StreamedRepoReader;
25
+ //# sourceMappingURL=stream-repo-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-repo-reader.d.ts","sourceRoot":"","sources":["../../../lib/v4/repo-reader/stream-repo-reader.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAUvC,MAAM,MAAM,iBAAiB,GAC1B;IACA,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACX,GACD;IACA,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;CAChB,GACD;IACA,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;CACd,CAAC;AAEL,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAErD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;CACnD;AAED,eAAO,MAAM,kBAAkB,QAAO,oBAAoB,CAAC,SAAS,EAAE,UAAU,CA6B/E,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,cAAc,CAAC,UAAU,CAAC,KAAG,kBAiI/D,CAAC"}
@@ -46,91 +46,97 @@ export const fromStream = (stream) => {
46
46
  return this.dispose();
47
47
  },
48
48
  async *[Symbol.asyncIterator]() {
49
- await using car = CarReader.fromStream(stream);
50
- const pending = new Map();
51
- const strays = new Map();
52
- const queue = new Queue();
53
- const request = (cid, meta) => {
54
- const entry = strays.get(cid);
55
- if (entry !== undefined) {
56
- strays.delete(cid);
57
- queue.enqueue({ c: cid, e: entry, m: meta });
58
- }
59
- else {
60
- pending.set(cid, meta);
61
- }
62
- };
63
- {
64
- const roots = await car.roots();
65
- assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
66
- const rootCid = roots[0].$link;
67
- request(rootCid, { t: 0 });
68
- }
69
- for await (const entry of car) {
70
- const cid = CID.toString(entry.cid);
71
- {
72
- const meta = pending.get(cid);
73
- if (meta !== undefined) {
74
- pending.delete(cid);
49
+ // await using car = CarReader.fromStream(stream);
50
+ const car = CarReader.fromStream(stream);
51
+ try {
52
+ const pending = new Map();
53
+ const strays = new Map();
54
+ const queue = new Queue();
55
+ const request = (cid, meta) => {
56
+ const entry = strays.get(cid);
57
+ if (entry !== undefined) {
58
+ strays.delete(cid);
75
59
  queue.enqueue({ c: cid, e: entry, m: meta });
76
60
  }
77
61
  else {
78
- strays.set(cid, entry);
62
+ pending.set(cid, meta);
79
63
  }
64
+ };
65
+ {
66
+ const roots = await car.roots();
67
+ assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
68
+ const rootCid = roots[0].$link;
69
+ request(rootCid, { t: 0 });
80
70
  }
81
- let task;
82
- while ((task = queue.dequeue())) {
83
- const { c: cid, e: entry, m: meta } = task;
84
- switch (meta.t) {
85
- case 0: {
86
- const commit = CBOR.decode(entry.bytes);
87
- assert(isCommit(commit), `expected commit block; cid=${cid}`);
88
- request(commit.data.$link, { t: 1 });
89
- break;
71
+ for await (const entry of car) {
72
+ const cid = CID.toString(entry.cid);
73
+ {
74
+ const meta = pending.get(cid);
75
+ if (meta !== undefined) {
76
+ pending.delete(cid);
77
+ queue.enqueue({ c: cid, e: entry, m: meta });
90
78
  }
91
- case 1: {
92
- const node = CBOR.decode(entry.bytes);
93
- assert(isMstNode(node), `expected mst node block; cid=${cid}`);
94
- const entries = node.e;
95
- const left = node.l;
96
- let lastKey = '';
97
- if (left !== null) {
98
- request(left.$link, meta);
79
+ else {
80
+ strays.set(cid, entry);
81
+ }
82
+ }
83
+ let task;
84
+ while ((task = queue.dequeue())) {
85
+ const { c: cid, e: entry, m: meta } = task;
86
+ switch (meta.t) {
87
+ case 0: {
88
+ const commit = CBOR.decode(entry.bytes);
89
+ assert(isCommit(commit), `expected commit block; cid=${cid}`);
90
+ request(commit.data.$link, { t: 1 });
91
+ break;
99
92
  }
100
- for (let i = 0, il = entries.length; i < il; i++) {
101
- const entry = entries[i];
102
- const next = entry.t;
103
- const key_str = decodeUtf8From(CBOR.fromBytes(entry.k));
104
- const key = lastKey.slice(0, entry.p) + key_str;
105
- lastKey = key;
106
- request(entry.v.$link, { t: 2, k: key });
107
- if (next !== null) {
108
- request(next.$link, { t: 1 });
93
+ case 1: {
94
+ const node = CBOR.decode(entry.bytes);
95
+ assert(isMstNode(node), `expected mst node block; cid=${cid}`);
96
+ const entries = node.e;
97
+ const left = node.l;
98
+ let lastKey = '';
99
+ if (left !== null) {
100
+ request(left.$link, meta);
109
101
  }
102
+ for (let i = 0, il = entries.length; i < il; i++) {
103
+ const entry = entries[i];
104
+ const next = entry.t;
105
+ const key_str = decodeUtf8From(CBOR.fromBytes(entry.k));
106
+ const key = lastKey.slice(0, entry.p) + key_str;
107
+ lastKey = key;
108
+ request(entry.v.$link, { t: 2, k: key });
109
+ if (next !== null) {
110
+ request(next.$link, { t: 1 });
111
+ }
112
+ }
113
+ break;
114
+ }
115
+ case 2: {
116
+ const [collection, rkey] = meta.k.split('/');
117
+ yield new RepoEntry(collection, rkey, CID.toCidLink(entry.cid), entry);
118
+ break;
110
119
  }
111
- break;
120
+ }
121
+ }
122
+ }
123
+ missingBlocks = Array.from(pending, ([cid, meta]) => {
124
+ switch (meta.t) {
125
+ case 0: {
126
+ return { cid, type: 'commit' };
127
+ }
128
+ case 1: {
129
+ return { cid, type: 'mst-node' };
112
130
  }
113
131
  case 2: {
114
- const [collection, rkey] = meta.k.split('/');
115
- yield new RepoEntry(collection, rkey, CID.toCidLink(entry.cid), entry);
116
- break;
132
+ return { cid, type: 'record', key: meta.k };
117
133
  }
118
134
  }
119
- }
135
+ });
136
+ }
137
+ finally {
138
+ await car.dispose();
120
139
  }
121
- missingBlocks = Array.from(pending, ([cid, meta]) => {
122
- switch (meta.t) {
123
- case 0: {
124
- return { cid, type: 'commit' };
125
- }
126
- case 1: {
127
- return { cid, type: 'mst-node' };
128
- }
129
- case 2: {
130
- return { cid, type: 'record', key: meta.k };
131
- }
132
- }
133
- });
134
140
  },
135
141
  };
136
142
  };
@@ -1 +1 @@
1
- {"version":3,"file":"stream-repo-reader.js","sourceRoot":"","sources":["../../../lib/v4/repo-reader/stream-repo-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAsCvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAgD,EAAE;IACnF,MAAM,SAAS,GAAG,IAAI,eAAe,EAA0B,CAAC;IAChE,IAAI,IAAoC,CAAC;IAEzC,OAAO;QACN,QAAQ,EAAE,IAAI,cAAc,CAAC;YAC5B,KAAK,CAAC,KAAK,CAAC,UAAU;gBACrB,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAEtC,IAAI,CAAC;oBACJ,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;wBAChC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC3B,CAAC;oBAED,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;oBAErB,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvB,CAAC;YACF,CAAC;YACD,KAAK,CAAC,MAAM;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gCAED,MAAM;4BACP,CAAC;4BACD,KAAK,CAAC,CAAC,CAAC,CAAC;gCACR,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gCAE7C,MAAM,IAAI,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;gCACvE,MAAM;4BACP,CAAC;wBACF,CAAC;oBACF,CAAC;gBACF,CAAC;gBAED,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAqB,EAAE;oBACtE,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;wBAChB,KAAK,CAAC,CAAC,CAAC,CAAC;4BACR,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;wBAChC,CAAC;wBACD,KAAK,CAAC,CAAC,CAAC,CAAC;4BACR,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;wBAClC,CAAC;wBACD,KAAK,CAAC,CAAC,CAAC,CAAC;4BACR,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;wBAC7C,CAAC;oBACF,CAAC;gBACF,CAAC,CAAC,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACV,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC,CAAC"}
@@ -27,3 +27,4 @@ export interface NodeEntry {
27
27
  * @returns a generator that yields the entries of the MST
28
28
  */
29
29
  export declare function walkMstEntries(map: BlockMap, pointer: CID.CidLink): Generator<NodeEntry>;
30
+ //# sourceMappingURL=sync-blockmap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-blockmap.d.ts","sourceRoot":"","sources":["../../../lib/v4/repo-reader/sync-blockmap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAKpD,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAG,QAOrE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAC1B,KAAK,QAAQ,EACb,MAAM,GAAG,CAAC,OAAO,EACjB,UAAU,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,KACtC,CAUF,CAAC;AAEF,wBAAwB;AACxB,MAAM,WAAW,SAAS;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAiB,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAwBzF"}
@@ -1,2 +1,3 @@
1
1
  import { RepoEntry } from './types.js';
2
2
  export declare function fromUint8Array(buf: Uint8Array): Generator<RepoEntry>;
3
+ //# sourceMappingURL=sync-repo-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-repo-reader.d.ts","sourceRoot":"","sources":["../../../lib/v4/repo-reader/sync-repo-reader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,wBAAiB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,CAmBrE"}
@@ -18,3 +18,4 @@ export declare class RepoEntry {
18
18
  */
19
19
  get record(): unknown;
20
20
  }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/v4/repo-reader/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,qBAAa,SAAS;IAGpB,4CAA4C;aAC5B,UAAU,EAAE,MAAM;IAClC,iBAAiB;aACD,IAAI,EAAE,MAAM;IAC5B,yBAAyB;aACT,GAAG,EAAE,GAAG,CAAC,OAAO;IAChC,8CAA8C;aAC9B,QAAQ,EAAE,QAAQ;IAGnC;;OAEG;IACH,IAAI,KAAK,IAAI,UAAU,CAEtB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,OAAO,CAEpB;CACD"}
@@ -1,3 +1,4 @@
1
1
  export declare const assert: {
2
2
  (condition: boolean, message: string): asserts condition;
3
3
  };
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/v4/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,EAAE;IACpB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAKzD,CAAC"}
@@ -93,112 +93,117 @@ export const fromStream = (stream: ReadableStream<Uint8Array>): StreamedRepoRead
93
93
  return this.dispose();
94
94
  },
95
95
  async *[Symbol.asyncIterator]() {
96
- await using car = CarReader.fromStream(stream);
96
+ // await using car = CarReader.fromStream(stream);
97
+ const car = CarReader.fromStream(stream);
97
98
 
98
- const pending = new Map<string, EntryMeta>();
99
- const strays = new Map<string, CarReader.CarEntry>();
99
+ try {
100
+ const pending = new Map<string, EntryMeta>();
101
+ const strays = new Map<string, CarReader.CarEntry>();
100
102
 
101
- const queue = new Queue<Task>();
103
+ const queue = new Queue<Task>();
102
104
 
103
- const request = (cid: string, meta: EntryMeta): void => {
104
- const entry = strays.get(cid);
105
+ const request = (cid: string, meta: EntryMeta): void => {
106
+ const entry = strays.get(cid);
105
107
 
106
- if (entry !== undefined) {
107
- strays.delete(cid);
108
- queue.enqueue({ c: cid, e: entry, m: meta });
109
- } else {
110
- pending.set(cid, meta);
111
- }
112
- };
113
-
114
- {
115
- const roots = await car.roots();
116
- assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
117
-
118
- const rootCid = roots[0].$link;
119
- request(rootCid, { t: 0 });
120
- }
121
-
122
- for await (const entry of car) {
123
- const cid = CID.toString(entry.cid);
124
-
125
- {
126
- const meta = pending.get(cid);
127
-
128
- if (meta !== undefined) {
129
- pending.delete(cid);
108
+ if (entry !== undefined) {
109
+ strays.delete(cid);
130
110
  queue.enqueue({ c: cid, e: entry, m: meta });
131
111
  } else {
132
- strays.set(cid, entry);
112
+ pending.set(cid, meta);
133
113
  }
114
+ };
115
+
116
+ {
117
+ const roots = await car.roots();
118
+ assert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);
119
+
120
+ const rootCid = roots[0].$link;
121
+ request(rootCid, { t: 0 });
134
122
  }
135
123
 
136
- let task: Task | undefined;
137
- while ((task = queue.dequeue())) {
138
- const { c: cid, e: entry, m: meta } = task;
124
+ for await (const entry of car) {
125
+ const cid = CID.toString(entry.cid);
139
126
 
140
- switch (meta.t) {
141
- case 0: {
142
- const commit = CBOR.decode(entry.bytes);
143
- assert(isCommit(commit), `expected commit block; cid=${cid}`);
127
+ {
128
+ const meta = pending.get(cid);
144
129
 
145
- request(commit.data.$link, { t: 1 });
146
- break;
130
+ if (meta !== undefined) {
131
+ pending.delete(cid);
132
+ queue.enqueue({ c: cid, e: entry, m: meta });
133
+ } else {
134
+ strays.set(cid, entry);
147
135
  }
148
- case 1: {
149
- const node = CBOR.decode(entry.bytes);
150
- assert(isMstNode(node), `expected mst node block; cid=${cid}`);
136
+ }
151
137
 
152
- const entries = node.e;
153
- const left = node.l;
138
+ let task: Task | undefined;
139
+ while ((task = queue.dequeue())) {
140
+ const { c: cid, e: entry, m: meta } = task;
154
141
 
155
- let lastKey = '';
142
+ switch (meta.t) {
143
+ case 0: {
144
+ const commit = CBOR.decode(entry.bytes);
145
+ assert(isCommit(commit), `expected commit block; cid=${cid}`);
156
146
 
157
- if (left !== null) {
158
- request(left.$link, meta);
147
+ request(commit.data.$link, { t: 1 });
148
+ break;
159
149
  }
150
+ case 1: {
151
+ const node = CBOR.decode(entry.bytes);
152
+ assert(isMstNode(node), `expected mst node block; cid=${cid}`);
153
+
154
+ const entries = node.e;
155
+ const left = node.l;
156
+
157
+ let lastKey = '';
158
+
159
+ if (left !== null) {
160
+ request(left.$link, meta);
161
+ }
160
162
 
161
- for (let i = 0, il = entries.length; i < il; i++) {
162
- const entry = entries[i];
163
- const next = entry.t;
163
+ for (let i = 0, il = entries.length; i < il; i++) {
164
+ const entry = entries[i];
165
+ const next = entry.t;
164
166
 
165
- const key_str = decodeUtf8From(CBOR.fromBytes(entry.k));
166
- const key = lastKey.slice(0, entry.p) + key_str;
167
+ const key_str = decodeUtf8From(CBOR.fromBytes(entry.k));
168
+ const key = lastKey.slice(0, entry.p) + key_str;
167
169
 
168
- lastKey = key;
170
+ lastKey = key;
169
171
 
170
- request(entry.v.$link, { t: 2, k: key });
172
+ request(entry.v.$link, { t: 2, k: key });
171
173
 
172
- if (next !== null) {
173
- request(next.$link, { t: 1 });
174
+ if (next !== null) {
175
+ request(next.$link, { t: 1 });
176
+ }
174
177
  }
175
- }
176
178
 
177
- break;
178
- }
179
- case 2: {
180
- const [collection, rkey] = meta.k.split('/');
179
+ break;
180
+ }
181
+ case 2: {
182
+ const [collection, rkey] = meta.k.split('/');
181
183
 
182
- yield new RepoEntry(collection, rkey, CID.toCidLink(entry.cid), entry);
183
- break;
184
+ yield new RepoEntry(collection, rkey, CID.toCidLink(entry.cid), entry);
185
+ break;
186
+ }
184
187
  }
185
188
  }
186
189
  }
187
- }
188
190
 
189
- missingBlocks = Array.from(pending, ([cid, meta]): MissingBlockEntry => {
190
- switch (meta.t) {
191
- case 0: {
192
- return { cid, type: 'commit' };
193
- }
194
- case 1: {
195
- return { cid, type: 'mst-node' };
196
- }
197
- case 2: {
198
- return { cid, type: 'record', key: meta.k };
191
+ missingBlocks = Array.from(pending, ([cid, meta]): MissingBlockEntry => {
192
+ switch (meta.t) {
193
+ case 0: {
194
+ return { cid, type: 'commit' };
195
+ }
196
+ case 1: {
197
+ return { cid, type: 'mst-node' };
198
+ }
199
+ case 2: {
200
+ return { cid, type: 'record', key: meta.k };
201
+ }
199
202
  }
200
- }
201
- });
203
+ });
204
+ } finally {
205
+ await car.dispose();
206
+ }
202
207
  },
203
208
  };
204
209
  };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@atcute/car",
4
- "version": "3.1.0",
4
+ "version": "3.1.2",
5
5
  "description": "lightweight DASL CAR and atproto repository decoder for AT Protocol.",
6
6
  "keywords": [
7
7
  "atproto",
8
8
  "dasl",
9
9
  "car"
10
10
  ],
11
- "license": "MIT",
11
+ "license": "0BSD",
12
12
  "repository": {
13
13
  "url": "https://github.com/mary-ext/atcute",
14
14
  "directory": "packages/utilities/car"
@@ -27,15 +27,15 @@
27
27
  },
28
28
  "sideEffects": false,
29
29
  "devDependencies": {
30
- "@types/bun": "^1.2.13",
31
- "@atcute/multibase": "^1.1.4"
30
+ "@types/bun": "^1.2.21",
31
+ "@atcute/multibase": "^1.1.6"
32
32
  },
33
33
  "dependencies": {
34
34
  "yocto-queue": "^1.2.1",
35
- "@atcute/cbor": "^2.2.4",
36
- "@atcute/uint8array": "^1.0.2",
37
- "@atcute/varint": "^1.0.2",
38
- "@atcute/cid": "^2.2.3"
35
+ "@atcute/cbor": "^2.2.6",
36
+ "@atcute/cid": "^2.2.4",
37
+ "@atcute/uint8array": "^1.0.5",
38
+ "@atcute/varint": "^1.0.3"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc --project tsconfig.build.json",