@fireproof/vendor 1.0.3 → 1.1.0-dev
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/package.json +4 -97
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts +1 -53
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts +1 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/block.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/block.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/diff.d.ts +3 -3
- package/src/@web3-storage/pail/dist/src/diff.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/index.d.ts +1 -1
- package/src/@web3-storage/pail/dist/src/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/merge.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/shard.d.ts +4 -4
- package/src/@web3-storage/pail/dist/src/shard.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/tsconfig.tsbuildinfo +1 -1
- package/src/@web3-storage/pail/src/api.ts +1 -1
- package/src/@web3-storage/pail/src/clock/index.js +1 -1
- package/src/@web3-storage/pail/src/shard.js +1 -1
- package/src/@ipld/car/LICENSE +0 -4
- package/src/@ipld/car/README.md +0 -1132
- package/src/@ipld/car/dist/index.min.js +0 -5
- package/src/@ipld/car/dist/src/api.d.ts +0 -72
- package/src/@ipld/car/dist/src/api.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts +0 -67
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts +0 -116
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-reader.d.ts +0 -31
- package/src/@ipld/car/dist/src/buffer-reader.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-writer.d.ts +0 -86
- package/src/@ipld/car/dist/src/buffer-writer.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/coding.d.ts +0 -49
- package/src/@ipld/car/dist/src/coding.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/decoder-common.d.ts +0 -43
- package/src/@ipld/car/dist/src/decoder-common.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/decoder.d.ts +0 -87
- package/src/@ipld/car/dist/src/decoder.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/encoder.d.ts +0 -17
- package/src/@ipld/car/dist/src/encoder.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/header-validator.d.ts +0 -5
- package/src/@ipld/car/dist/src/header-validator.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/index-browser.d.ts +0 -10
- package/src/@ipld/car/dist/src/index-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/index.d.ts +0 -11
- package/src/@ipld/car/dist/src/index.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts +0 -5
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/indexed-reader.d.ts +0 -152
- package/src/@ipld/car/dist/src/indexed-reader.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/indexer.d.ts +0 -95
- package/src/@ipld/car/dist/src/indexer.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/iterator-channel.d.ts +0 -7
- package/src/@ipld/car/dist/src/iterator-channel.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/iterator.d.ts +0 -174
- package/src/@ipld/car/dist/src/iterator.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/reader-browser.d.ts +0 -151
- package/src/@ipld/car/dist/src/reader-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/reader.d.ts +0 -35
- package/src/@ipld/car/dist/src/reader.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/writer-browser.d.ts +0 -155
- package/src/@ipld/car/dist/src/writer-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/writer.d.ts +0 -45
- package/src/@ipld/car/dist/src/writer.d.ts.map +0 -1
- package/src/@ipld/car/src/api.ts +0 -90
- package/src/@ipld/car/src/buffer-decoder.js +0 -213
- package/src/@ipld/car/src/buffer-reader-browser.js +0 -144
- package/src/@ipld/car/src/buffer-reader.js +0 -51
- package/src/@ipld/car/src/buffer-writer.js +0 -286
- package/src/@ipld/car/src/coding.ts +0 -68
- package/src/@ipld/car/src/decoder-common.js +0 -82
- package/src/@ipld/car/src/decoder.js +0 -347
- package/src/@ipld/car/src/encoder.js +0 -76
- package/src/@ipld/car/src/header-validator.js +0 -214
- package/src/@ipld/car/src/header.ipldsch +0 -18
- package/src/@ipld/car/src/index-browser.js +0 -18
- package/src/@ipld/car/src/index.js +0 -21
- package/src/@ipld/car/src/indexed-reader-browser.js +0 -7
- package/src/@ipld/car/src/indexed-reader.js +0 -211
- package/src/@ipld/car/src/indexer.js +0 -130
- package/src/@ipld/car/src/iterator-channel.js +0 -91
- package/src/@ipld/car/src/iterator.js +0 -267
- package/src/@ipld/car/src/reader-browser.js +0 -194
- package/src/@ipld/car/src/reader.js +0 -73
- package/src/@ipld/car/src/writer-browser.js +0 -250
- package/src/@ipld/car/src/writer.js +0 -84
- package/src/@ipld/dag-cbor/LICENSE +0 -4
- package/src/@ipld/dag-cbor/README.md +0 -80
- package/src/@ipld/dag-cbor/dist/index.min.js +0 -3
- package/src/@ipld/dag-cbor/dist/src/index.d.ts +0 -67
- package/src/@ipld/dag-cbor/dist/src/index.d.ts.map +0 -1
- package/src/@ipld/dag-cbor/src/index.js +0 -147
- package/src/@ipld/dag-json/LICENSE +0 -4
- package/src/@ipld/dag-json/README.md +0 -58
- package/src/@ipld/dag-json/dist/index.min.js +0 -3
- package/src/@ipld/dag-json/dist/src/index.d.ts +0 -12
- package/src/@ipld/dag-json/dist/src/index.d.ts.map +0 -1
- package/src/@ipld/dag-json/src/index.js +0 -291
- package/src/cborg/.github/dependabot.yml +0 -16
- package/src/cborg/.github/workflows/test-and-release.yml +0 -52
- package/src/cborg/CHANGELOG.md +0 -513
- package/src/cborg/LICENSE +0 -13
- package/src/cborg/README.md +0 -515
- package/src/cborg/bench/bench.js +0 -117
- package/src/cborg/bench/json.js +0 -124
- package/src/cborg/bench/package.json +0 -8
- package/src/cborg/cborg/bin.js +0 -189
- package/src/cborg/cborg/common.js +0 -28
- package/src/cborg/cborg/decode.js +0 -211
- package/src/cborg/cborg/diagnostic.js +0 -158
- package/src/cborg/cborg/diagnostic_test.js +0 -117
- package/src/cborg/cborg/encode.js +0 -466
- package/src/cborg/cborg/index.js +0 -33
- package/src/cborg/cborg/is.js +0 -106
- package/src/cborg/cborg/length.js +0 -62
- package/src/cborg/example-bytestrings.js +0 -180
- package/src/cborg/example-json.js +0 -6
- package/src/cborg/example.js +0 -5
- package/src/cborg/interface.ts +0 -59
- package/src/cborg/json/decode.js +0 -462
- package/src/cborg/json/encode.js +0 -302
- package/src/cborg/json/json.js +0 -4
- package/src/cborg/taglib.js +0 -75
- package/src/cborg/test/appendix_a.js +0 -647
- package/src/cborg/test/common.js +0 -18
- package/src/cborg/test/node-test-bin.js +0 -402
- package/src/cborg/test/noop-bin-test.js +0 -3
- package/src/cborg/test/test-0uint.js +0 -103
- package/src/cborg/test/test-1negint.js +0 -96
- package/src/cborg/test/test-2bytes.js +0 -198
- package/src/cborg/test/test-3string.js +0 -136
- package/src/cborg/test/test-4array.js +0 -93
- package/src/cborg/test/test-5map.js +0 -284
- package/src/cborg/test/test-6tag.js +0 -84
- package/src/cborg/test/test-7float.js +0 -131
- package/src/cborg/test/test-bl.js +0 -37
- package/src/cborg/test/test-cbor-vectors.js +0 -107
- package/src/cborg/test/test-decode-errors.js +0 -65
- package/src/cborg/test/test-fuzz.js +0 -42
- package/src/cborg/test/test-json.js +0 -219
- package/src/cborg/test/test-length.js +0 -65
- package/src/cborg/test/test-partial.js +0 -111
- package/src/cborg/tsconfig.json +0 -48
- package/src/cborg/types/cborg/decode.d.ts +0 -43
- package/src/cborg/types/cborg/decode.d.ts.map +0 -1
- package/src/cborg/types/cborg/encode.d.ts +0 -51
- package/src/cborg/types/cborg/encode.d.ts.map +0 -1
- package/src/cborg/types/cborg/index.d.ts +0 -26
- package/src/cborg/types/cborg/index.d.ts.map +0 -1
- package/src/cborg/types/cborg/is.d.ts +0 -6
- package/src/cborg/types/cborg/is.d.ts.map +0 -1
- package/src/cborg/types/example.d.ts +0 -2
- package/src/cborg/types/example.d.ts.map +0 -1
- package/src/cborg/types/interface.d.ts +0 -49
- package/src/cborg/types/interface.d.ts.map +0 -1
- package/src/cborg/types/json/decode.d.ts +0 -67
- package/src/cborg/types/json/decode.d.ts.map +0 -1
- package/src/cborg/types/json/encode.d.ts +0 -11
- package/src/cborg/types/json/encode.d.ts.map +0 -1
- package/src/cborg/types/json/json.d.ts +0 -6
- package/src/cborg/types/json/json.d.ts.map +0 -1
- package/src/cborg/types/taglib.d.ts +0 -18
- package/src/cborg/types/taglib.d.ts.map +0 -1
- package/src/cborg/types/tsconfig.tsbuildinfo +0 -1
- package/src/cborg/types/utils/0uint.d.ts +0 -102
- package/src/cborg/types/utils/0uint.d.ts.map +0 -1
- package/src/cborg/types/utils/1negint.d.ts +0 -59
- package/src/cborg/types/utils/1negint.d.ts.map +0 -1
- package/src/cborg/types/utils/2bytes.d.ts +0 -69
- package/src/cborg/types/utils/2bytes.d.ts.map +0 -1
- package/src/cborg/types/utils/3string.d.ts +0 -46
- package/src/cborg/types/utils/3string.d.ts.map +0 -1
- package/src/cborg/types/utils/4array.d.ts +0 -66
- package/src/cborg/types/utils/4array.d.ts.map +0 -1
- package/src/cborg/types/utils/5map.d.ts +0 -66
- package/src/cborg/types/utils/5map.d.ts.map +0 -1
- package/src/cborg/types/utils/6tag.d.ts +0 -62
- package/src/cborg/types/utils/6tag.d.ts.map +0 -1
- package/src/cborg/types/utils/7float.d.ts +0 -60
- package/src/cborg/types/utils/7float.d.ts.map +0 -1
- package/src/cborg/types/utils/bl.d.ts +0 -26
- package/src/cborg/types/utils/bl.d.ts.map +0 -1
- package/src/cborg/types/utils/byte-utils.d.ts +0 -53
- package/src/cborg/types/utils/byte-utils.d.ts.map +0 -1
- package/src/cborg/types/utils/common.d.ts +0 -8
- package/src/cborg/types/utils/common.d.ts.map +0 -1
- package/src/cborg/types/utils/index.d.ts +0 -13
- package/src/cborg/types/utils/index.d.ts.map +0 -1
- package/src/cborg/types/utils/jump.d.ts +0 -16
- package/src/cborg/types/utils/jump.d.ts.map +0 -1
- package/src/cborg/types/utils/token.d.ts +0 -59
- package/src/cborg/types/utils/token.d.ts.map +0 -1
- package/src/cborg/utils/0uint.js +0 -229
- package/src/cborg/utils/1negint.js +0 -111
- package/src/cborg/utils/2bytes.js +0 -135
- package/src/cborg/utils/3string.js +0 -90
- package/src/cborg/utils/4array.js +0 -114
- package/src/cborg/utils/5map.js +0 -113
- package/src/cborg/utils/6tag.js +0 -81
- package/src/cborg/utils/7float.js +0 -310
- package/src/cborg/utils/bl.js +0 -124
- package/src/cborg/utils/byte-utils.js +0 -417
- package/src/cborg/utils/common.js +0 -11
- package/src/cborg/utils/index.js +0 -12
- package/src/cborg/utils/jump.js +0 -222
- package/src/cborg/utils/token.js +0 -76
- package/src/ipfs-unixfs-exporter/LICENSE +0 -4
- package/src/ipfs-unixfs-exporter/README.md +0 -105
- package/src/ipfs-unixfs-exporter/dist/index.min.js +0 -3
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts +0 -57
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/errors.js +0 -73
- package/src/ipfs-unixfs-exporter/dist/src/errors.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts +0 -355
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/index.js +0 -197
- package/src/ipfs-unixfs-exporter/dist/src/index.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +0 -9
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +0 -9
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +0 -38
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js +0 -30
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js +0 -9
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +0 -37
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +0 -29
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +0 -153
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +0 -59
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +0 -25
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +0 -104
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +0 -3
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +0 -20
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +0 -6
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +0 -116
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +0 -57
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +0 -6
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +0 -30
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/typedoc-urls.json +0 -58
- package/src/ipfs-unixfs-exporter/src/errors.ts +0 -87
- package/src/ipfs-unixfs-exporter/src/index.ts +0 -498
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +0 -12
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +0 -12
- package/src/ipfs-unixfs-exporter/src/resolvers/identity.ts +0 -49
- package/src/ipfs-unixfs-exporter/src/resolvers/index.ts +0 -35
- package/src/ipfs-unixfs-exporter/src/resolvers/json.ts +0 -12
- package/src/ipfs-unixfs-exporter/src/resolvers/raw.ts +0 -49
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +0 -39
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +0 -198
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +0 -76
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +0 -37
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +0 -121
- package/src/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +0 -24
- package/src/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +0 -149
- package/src/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +0 -62
- package/src/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +0 -38
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/** Auto-generated with @ipld/schema@v4.2.0 at Thu Sep 14 2023 from IPLD Schema:
|
|
2
|
-
*
|
|
3
|
-
* # CarV1HeaderOrV2Pragma is a more relaxed form, and can parse {version:x} where
|
|
4
|
-
* # roots are optional. This is typically useful for the {verison:2} CARv2
|
|
5
|
-
* # pragma.
|
|
6
|
-
*
|
|
7
|
-
* type CarV1HeaderOrV2Pragma struct {
|
|
8
|
-
* roots optional [&Any]
|
|
9
|
-
* # roots is _not_ optional for CarV1 but we defer that check within code to
|
|
10
|
-
* # gracefully handle the V2 case where it's just {version:X}
|
|
11
|
-
* version Int
|
|
12
|
-
* }
|
|
13
|
-
*
|
|
14
|
-
* # CarV1Header is the strict form of the header, and requires roots to be
|
|
15
|
-
* # present. This is compatible with the CARv1 specification.
|
|
16
|
-
*
|
|
17
|
-
* # type CarV1Header struct {
|
|
18
|
-
* # roots [&Any]
|
|
19
|
-
* # version Int
|
|
20
|
-
* # }
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const Kinds = {
|
|
25
|
-
Null: /** @returns {undefined|null} */ (/** @type {any} */ obj) => obj === null ? obj : undefined,
|
|
26
|
-
Int: /** @returns {undefined|number} */ (/** @type {any} */ obj) => Number.isInteger(obj) ? obj : undefined,
|
|
27
|
-
Float: /** @returns {undefined|number} */ (/** @type {any} */ obj) => typeof obj === 'number' && Number.isFinite(obj) ? obj : undefined,
|
|
28
|
-
String: /** @returns {undefined|string} */ (/** @type {any} */ obj) => typeof obj === 'string' ? obj : undefined,
|
|
29
|
-
Bool: /** @returns {undefined|boolean} */ (/** @type {any} */ obj) => typeof obj === 'boolean' ? obj : undefined,
|
|
30
|
-
Bytes: /** @returns {undefined|Uint8Array} */ (/** @type {any} */ obj) => obj instanceof Uint8Array ? obj : undefined,
|
|
31
|
-
Link: /** @returns {undefined|object} */ (/** @type {any} */ obj) => obj !== null && typeof obj === 'object' && obj.asCID === obj ? obj : undefined,
|
|
32
|
-
List: /** @returns {undefined|Array<any>} */ (/** @type {any} */ obj) => Array.isArray(obj) ? obj : undefined,
|
|
33
|
-
Map: /** @returns {undefined|object} */ (/** @type {any} */ obj) => obj !== null && typeof obj === 'object' && obj.asCID !== obj && !Array.isArray(obj) && !(obj instanceof Uint8Array) ? obj : undefined
|
|
34
|
-
}
|
|
35
|
-
/** @type {{ [k in string]: (obj:any)=>undefined|any}} */
|
|
36
|
-
const Types = {
|
|
37
|
-
'CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)': Kinds.Link,
|
|
38
|
-
'CarV1HeaderOrV2Pragma > roots (anon)': /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
39
|
-
if (Kinds.List(obj) === undefined) {
|
|
40
|
-
return undefined
|
|
41
|
-
}
|
|
42
|
-
for (let i = 0; i < obj.length; i++) {
|
|
43
|
-
let v = obj[i]
|
|
44
|
-
v = Types['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
45
|
-
if (v === undefined) {
|
|
46
|
-
return undefined
|
|
47
|
-
}
|
|
48
|
-
if (v !== obj[i]) {
|
|
49
|
-
const ret = obj.slice(0, i)
|
|
50
|
-
for (let j = i; j < obj.length; j++) {
|
|
51
|
-
let v = obj[j]
|
|
52
|
-
v = Types['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
53
|
-
if (v === undefined) {
|
|
54
|
-
return undefined
|
|
55
|
-
}
|
|
56
|
-
ret.push(v)
|
|
57
|
-
}
|
|
58
|
-
return ret
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return obj
|
|
62
|
-
},
|
|
63
|
-
Int: Kinds.Int,
|
|
64
|
-
CarV1HeaderOrV2Pragma: /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
65
|
-
if (Kinds.Map(obj) === undefined) {
|
|
66
|
-
return undefined
|
|
67
|
-
}
|
|
68
|
-
const entries = Object.entries(obj)
|
|
69
|
-
/** @type {{[k in string]: any}} */
|
|
70
|
-
let ret = obj
|
|
71
|
-
let requiredCount = 1
|
|
72
|
-
for (let i = 0; i < entries.length; i++) {
|
|
73
|
-
const [key, value] = entries[i]
|
|
74
|
-
switch (key) {
|
|
75
|
-
case 'roots':
|
|
76
|
-
{
|
|
77
|
-
const v = Types['CarV1HeaderOrV2Pragma > roots (anon)'](obj[key])
|
|
78
|
-
if (v === undefined) {
|
|
79
|
-
return undefined
|
|
80
|
-
}
|
|
81
|
-
if (v !== value || ret !== obj) {
|
|
82
|
-
if (ret === obj) {
|
|
83
|
-
/** @type {{[k in string]: any}} */
|
|
84
|
-
ret = {}
|
|
85
|
-
for (let j = 0; j < i; j++) {
|
|
86
|
-
ret[entries[j][0]] = entries[j][1]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
ret.roots = v
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
break
|
|
93
|
-
case 'version':
|
|
94
|
-
{
|
|
95
|
-
requiredCount--
|
|
96
|
-
const v = Types.Int(obj[key])
|
|
97
|
-
if (v === undefined) {
|
|
98
|
-
return undefined
|
|
99
|
-
}
|
|
100
|
-
if (v !== value || ret !== obj) {
|
|
101
|
-
if (ret === obj) {
|
|
102
|
-
/** @type {{[k in string]: any}} */
|
|
103
|
-
ret = {}
|
|
104
|
-
for (let j = 0; j < i; j++) {
|
|
105
|
-
ret[entries[j][0]] = entries[j][1]
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
ret.version = v
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
break
|
|
112
|
-
default:
|
|
113
|
-
return undefined
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (requiredCount > 0) {
|
|
118
|
-
return undefined
|
|
119
|
-
}
|
|
120
|
-
return ret
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/** @type {{ [k in string]: (obj:any)=>undefined|any}} */
|
|
124
|
-
const Reprs = {
|
|
125
|
-
'CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)': Kinds.Link,
|
|
126
|
-
'CarV1HeaderOrV2Pragma > roots (anon)': /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
127
|
-
if (Kinds.List(obj) === undefined) {
|
|
128
|
-
return undefined
|
|
129
|
-
}
|
|
130
|
-
for (let i = 0; i < obj.length; i++) {
|
|
131
|
-
let v = obj[i]
|
|
132
|
-
v = Reprs['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
133
|
-
if (v === undefined) {
|
|
134
|
-
return undefined
|
|
135
|
-
}
|
|
136
|
-
if (v !== obj[i]) {
|
|
137
|
-
const ret = obj.slice(0, i)
|
|
138
|
-
for (let j = i; j < obj.length; j++) {
|
|
139
|
-
let v = obj[j]
|
|
140
|
-
v = Reprs['CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)'](v)
|
|
141
|
-
if (v === undefined) {
|
|
142
|
-
return undefined
|
|
143
|
-
}
|
|
144
|
-
ret.push(v)
|
|
145
|
-
}
|
|
146
|
-
return ret
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return obj
|
|
150
|
-
},
|
|
151
|
-
Int: Kinds.Int,
|
|
152
|
-
CarV1HeaderOrV2Pragma: /** @returns {undefined|any} */ (/** @type {any} */ obj) => {
|
|
153
|
-
if (Kinds.Map(obj) === undefined) {
|
|
154
|
-
return undefined
|
|
155
|
-
}
|
|
156
|
-
const entries = Object.entries(obj)
|
|
157
|
-
/** @type {{[k in string]: any}} */
|
|
158
|
-
let ret = obj
|
|
159
|
-
let requiredCount = 1
|
|
160
|
-
for (let i = 0; i < entries.length; i++) {
|
|
161
|
-
const [key, value] = entries[i]
|
|
162
|
-
switch (key) {
|
|
163
|
-
case 'roots':
|
|
164
|
-
{
|
|
165
|
-
const v = Reprs['CarV1HeaderOrV2Pragma > roots (anon)'](value)
|
|
166
|
-
if (v === undefined) {
|
|
167
|
-
return undefined
|
|
168
|
-
}
|
|
169
|
-
if (v !== value || ret !== obj) {
|
|
170
|
-
if (ret === obj) {
|
|
171
|
-
/** @type {{[k in string]: any}} */
|
|
172
|
-
ret = {}
|
|
173
|
-
for (let j = 0; j < i; j++) {
|
|
174
|
-
ret[entries[j][0]] = entries[j][1]
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
ret.roots = v
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
break
|
|
181
|
-
case 'version':
|
|
182
|
-
{
|
|
183
|
-
requiredCount--
|
|
184
|
-
const v = Reprs.Int(value)
|
|
185
|
-
if (v === undefined) {
|
|
186
|
-
return undefined
|
|
187
|
-
}
|
|
188
|
-
if (v !== value || ret !== obj) {
|
|
189
|
-
if (ret === obj) {
|
|
190
|
-
/** @type {{[k in string]: any}} */
|
|
191
|
-
ret = {}
|
|
192
|
-
for (let j = 0; j < i; j++) {
|
|
193
|
-
ret[entries[j][0]] = entries[j][1]
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
ret.version = v
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
break
|
|
200
|
-
default:
|
|
201
|
-
return undefined
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (requiredCount > 0) {
|
|
205
|
-
return undefined
|
|
206
|
-
}
|
|
207
|
-
return ret
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export const CarV1HeaderOrV2Pragma = {
|
|
212
|
-
toTyped: Types.CarV1HeaderOrV2Pragma,
|
|
213
|
-
toRepresentation: Reprs.CarV1HeaderOrV2Pragma
|
|
214
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# CarV1HeaderOrV2Pragma is a more relaxed form, and can parse {version:x} where
|
|
2
|
-
# roots are optional. This is typically useful for the {verison:2} CARv2
|
|
3
|
-
# pragma.
|
|
4
|
-
|
|
5
|
-
type CarV1HeaderOrV2Pragma struct {
|
|
6
|
-
roots optional [&Any]
|
|
7
|
-
# roots is _not_ optional for CarV1 but we defer that check within code to
|
|
8
|
-
# gracefully handle the V2 case where it's just {version:X}
|
|
9
|
-
version Int
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
# CarV1Header is the strict form of the header, and requires roots to be
|
|
13
|
-
# present. This is compatible with the CARv1 specification.
|
|
14
|
-
|
|
15
|
-
# type CarV1Header struct {
|
|
16
|
-
# roots [&Any]
|
|
17
|
-
# version Int
|
|
18
|
-
# }
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { CarBufferReader } from './buffer-reader.js'
|
|
2
|
-
import * as CarBufferWriter from './buffer-writer.js'
|
|
3
|
-
import { CarIndexedReader } from './indexed-reader-browser.js'
|
|
4
|
-
import { CarIndexer } from './indexer.js'
|
|
5
|
-
import { CarBlockIterator, CarCIDIterator } from './iterator.js'
|
|
6
|
-
import { CarReader } from './reader-browser.js'
|
|
7
|
-
import { CarWriter } from './writer-browser.js'
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
CarReader,
|
|
11
|
-
CarIndexer,
|
|
12
|
-
CarBlockIterator,
|
|
13
|
-
CarCIDIterator,
|
|
14
|
-
CarWriter,
|
|
15
|
-
CarIndexedReader,
|
|
16
|
-
CarBufferReader,
|
|
17
|
-
CarBufferWriter
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CarBufferReader } from './buffer-reader.js'
|
|
2
|
-
import * as CarBufferWriter from './buffer-writer.js'
|
|
3
|
-
import { CarIndexedReader } from './indexed-reader.js'
|
|
4
|
-
import { CarIndexer } from './indexer.js'
|
|
5
|
-
import { CarBlockIterator, CarCIDIterator } from './iterator.js'
|
|
6
|
-
import { CarReader } from './reader.js'
|
|
7
|
-
import { CarWriter } from './writer.js'
|
|
8
|
-
|
|
9
|
-
// @see https://www.iana.org/assignments/media-types/application/vnd.ipld.car
|
|
10
|
-
export const contentType = 'application/vnd.ipld.car'
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
CarReader,
|
|
14
|
-
CarBufferReader,
|
|
15
|
-
CarIndexer,
|
|
16
|
-
CarBlockIterator,
|
|
17
|
-
CarCIDIterator,
|
|
18
|
-
CarWriter,
|
|
19
|
-
CarIndexedReader,
|
|
20
|
-
CarBufferWriter
|
|
21
|
-
}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import { Readable } from 'stream'
|
|
3
|
-
import { CID } from 'multiformats/cid'
|
|
4
|
-
import { CarIndexer } from './indexer.js'
|
|
5
|
-
import { CarReader as NodeCarReader } from './reader.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {import('fs').promises.FileHandle} FileHandle
|
|
9
|
-
* @typedef {import('./api').Block} Block
|
|
10
|
-
* @typedef {import('./api').BlockIndex} BlockIndex
|
|
11
|
-
* @typedef {import('./api').CarReader} CarReaderIface
|
|
12
|
-
* @typedef {import('./reader-browser').CarReader} CarReader
|
|
13
|
-
* @typedef {{ blockLength:number, blockOffset:number }} RawLocation
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A form of {@link CarReader} that pre-indexes a CAR archive from a file and
|
|
18
|
-
* provides random access to blocks within the file using the index data. This
|
|
19
|
-
* function is **only available in Node.js** and not a browser environment.
|
|
20
|
-
*
|
|
21
|
-
* For large CAR files, using this form of `CarReader` can be singificantly more
|
|
22
|
-
* efficient in terms of memory. The index consists of a list of `CID`s and
|
|
23
|
-
* their location within the archive (see {@link CarIndexer}). For large numbers
|
|
24
|
-
* of blocks, this index can also occupy a significant amount of memory. In some
|
|
25
|
-
* cases it may be necessary to expand the memory capacity of a Node.js instance
|
|
26
|
-
* to allow this index to fit. (e.g. by running with
|
|
27
|
-
* `NODE_OPTIONS="--max-old-space-size=16384"`).
|
|
28
|
-
*
|
|
29
|
-
* As an `CarIndexedReader` instance maintains an open file descriptor for its
|
|
30
|
-
* CAR file, an additional {@link CarReader#close} method is attached. This
|
|
31
|
-
* _must_ be called to have full clean-up of resources after use.
|
|
32
|
-
*
|
|
33
|
-
* Load this class with either
|
|
34
|
-
* `import { CarIndexedReader } from '@ipld/car/indexed-reader'`
|
|
35
|
-
* (`const { CarIndexedReader } = require('@ipld/car/indexed-reader')`). Or
|
|
36
|
-
* `import { CarIndexedReader } from '@ipld/car'`
|
|
37
|
-
* (`const { CarIndexedReader } = require('@ipld/car')`). The former will likely
|
|
38
|
-
* result in smaller bundle sizes where this is important.
|
|
39
|
-
*
|
|
40
|
-
* @name CarIndexedReader
|
|
41
|
-
* @class
|
|
42
|
-
* @implements {CarReaderIface}
|
|
43
|
-
* @extends {CarReader}
|
|
44
|
-
* @property {number} version The version number of the CAR referenced by this
|
|
45
|
-
* reader (should be `1`).
|
|
46
|
-
*/
|
|
47
|
-
export class CarIndexedReader {
|
|
48
|
-
/**
|
|
49
|
-
* @param {number} version
|
|
50
|
-
* @param {string} path
|
|
51
|
-
* @param {CID[]} roots
|
|
52
|
-
* @param {Map<string, RawLocation>} index
|
|
53
|
-
* @param {string[]} order
|
|
54
|
-
*/
|
|
55
|
-
constructor (version, path, roots, index, order) {
|
|
56
|
-
this._version = version
|
|
57
|
-
this._path = path
|
|
58
|
-
this._roots = roots
|
|
59
|
-
this._index = index
|
|
60
|
-
this._order = order
|
|
61
|
-
this._fd = null
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get version () {
|
|
65
|
-
return this._version
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* See {@link CarReader#getRoots}
|
|
70
|
-
*
|
|
71
|
-
* @function
|
|
72
|
-
* @memberof CarIndexedReader
|
|
73
|
-
* @instance
|
|
74
|
-
* @async
|
|
75
|
-
* @returns {Promise<CID[]>}
|
|
76
|
-
*/
|
|
77
|
-
async getRoots () {
|
|
78
|
-
return this._roots
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* See {@link CarReader#has}
|
|
83
|
-
*
|
|
84
|
-
* @function
|
|
85
|
-
* @memberof CarIndexedReader
|
|
86
|
-
* @instance
|
|
87
|
-
* @async
|
|
88
|
-
* @param {CID} key
|
|
89
|
-
* @returns {Promise<boolean>}
|
|
90
|
-
*/
|
|
91
|
-
async has (key) {
|
|
92
|
-
return this._index.has(key.toString())
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* See {@link CarReader#get}
|
|
97
|
-
*
|
|
98
|
-
* @function
|
|
99
|
-
* @memberof CarIndexedReader
|
|
100
|
-
* @instance
|
|
101
|
-
* @async
|
|
102
|
-
* @param {CID} key
|
|
103
|
-
* @returns {Promise<Block | undefined>}
|
|
104
|
-
*/
|
|
105
|
-
async get (key) {
|
|
106
|
-
const blockIndex = this._index.get(key.toString())
|
|
107
|
-
if (!blockIndex) {
|
|
108
|
-
return undefined
|
|
109
|
-
}
|
|
110
|
-
if (!this._fd) {
|
|
111
|
-
this._fd = await fs.promises.open(this._path, 'r')
|
|
112
|
-
}
|
|
113
|
-
const readIndex = {
|
|
114
|
-
cid: key,
|
|
115
|
-
length: 0,
|
|
116
|
-
offset: 0,
|
|
117
|
-
blockLength: blockIndex.blockLength,
|
|
118
|
-
blockOffset: blockIndex.blockOffset
|
|
119
|
-
}
|
|
120
|
-
return NodeCarReader.readRaw(this._fd, readIndex)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* See {@link CarReader#blocks}
|
|
125
|
-
*
|
|
126
|
-
* @function
|
|
127
|
-
* @memberof CarIndexedReader
|
|
128
|
-
* @instance
|
|
129
|
-
* @async
|
|
130
|
-
* @generator
|
|
131
|
-
* @returns {AsyncGenerator<Block>}
|
|
132
|
-
*/
|
|
133
|
-
async * blocks () {
|
|
134
|
-
for (const cidStr of this._order) {
|
|
135
|
-
const block = await this.get(CID.parse(cidStr))
|
|
136
|
-
/* c8 ignore next 3 */
|
|
137
|
-
if (!block) {
|
|
138
|
-
throw new Error('Unexpected internal error')
|
|
139
|
-
}
|
|
140
|
-
yield block
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* See {@link CarReader#cids}
|
|
146
|
-
*
|
|
147
|
-
* @function
|
|
148
|
-
* @memberof CarIndexedReader
|
|
149
|
-
* @instance
|
|
150
|
-
* @async
|
|
151
|
-
* @generator
|
|
152
|
-
* @returns {AsyncGenerator<CID>}
|
|
153
|
-
*/
|
|
154
|
-
async * cids () {
|
|
155
|
-
for (const cidStr of this._order) {
|
|
156
|
-
yield CID.parse(cidStr)
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Close the underlying file descriptor maintained by this `CarIndexedReader`.
|
|
162
|
-
* This must be called for proper resource clean-up to occur.
|
|
163
|
-
*
|
|
164
|
-
* @function
|
|
165
|
-
* @memberof CarIndexedReader
|
|
166
|
-
* @instance
|
|
167
|
-
* @async
|
|
168
|
-
* @returns {Promise<void>}
|
|
169
|
-
*/
|
|
170
|
-
async close () {
|
|
171
|
-
if (this._fd) {
|
|
172
|
-
return this._fd.close()
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Instantiate an {@link CarIndexedReader} from a file with the provided
|
|
178
|
-
* `path`. The CAR file is first indexed with a full path that collects `CID`s
|
|
179
|
-
* and block locations. This index is maintained in memory. Subsequent reads
|
|
180
|
-
* operate on a read-only file descriptor, fetching the block from its in-file
|
|
181
|
-
* location.
|
|
182
|
-
*
|
|
183
|
-
* For large archives, the initial indexing may take some time. The returned
|
|
184
|
-
* `Promise` will resolve only after this is complete.
|
|
185
|
-
*
|
|
186
|
-
* @async
|
|
187
|
-
* @static
|
|
188
|
-
* @memberof CarIndexedReader
|
|
189
|
-
* @param {string} path
|
|
190
|
-
* @returns {Promise<CarIndexedReader>}
|
|
191
|
-
*/
|
|
192
|
-
static async fromFile (path) {
|
|
193
|
-
if (typeof path !== 'string') {
|
|
194
|
-
throw new TypeError('fromFile() requires a file path string')
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const iterable = await CarIndexer.fromIterable(Readable.from(fs.createReadStream(path)))
|
|
198
|
-
/** @type {Map<string, RawLocation>} */
|
|
199
|
-
const index = new Map()
|
|
200
|
-
/** @type {string[]} */
|
|
201
|
-
const order = []
|
|
202
|
-
for await (const { cid, blockLength, blockOffset } of iterable) {
|
|
203
|
-
const cidStr = cid.toString()
|
|
204
|
-
index.set(cidStr, { blockLength, blockOffset })
|
|
205
|
-
order.push(cidStr)
|
|
206
|
-
}
|
|
207
|
-
return new CarIndexedReader(iterable.version, path, await iterable.getRoots(), index, order)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export const __browser = false
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
asyncIterableReader,
|
|
3
|
-
bytesReader,
|
|
4
|
-
createDecoder
|
|
5
|
-
} from './decoder.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {import('multiformats').CID} CID
|
|
9
|
-
* @typedef {import('./api').Block} Block
|
|
10
|
-
* @typedef {import('./api').RootsReader} RootsReader
|
|
11
|
-
* @typedef {import('./api').BlockIndex} BlockIndex
|
|
12
|
-
* @typedef {import('./coding').BytesReader} BytesReader
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Provides an iterator over all of the `Block`s in a CAR, returning their CIDs
|
|
17
|
-
* and byte-location information. Implements an `AsyncIterable<BlockIndex>`.
|
|
18
|
-
* Where a `BlockIndex` is a
|
|
19
|
-
* `{ cid:CID, length:number, offset:number, blockLength:number, blockOffset:number }`.
|
|
20
|
-
*
|
|
21
|
-
* As an implementer of `AsyncIterable`, this class can be used directly in a
|
|
22
|
-
* `for await (const blockIndex of iterator) {}` loop. Where the `iterator` is
|
|
23
|
-
* constructed using {@link CarIndexer.fromBytes} or
|
|
24
|
-
* {@link CarIndexer.fromIterable}.
|
|
25
|
-
*
|
|
26
|
-
* An iteration can only be performce _once_ per instantiation.
|
|
27
|
-
*
|
|
28
|
-
* `CarIndexer` also implements the `RootsReader` interface and provides
|
|
29
|
-
* the {@link CarIndexer.getRoots `getRoots()`} method.
|
|
30
|
-
*
|
|
31
|
-
* Load this class with either
|
|
32
|
-
* `import { CarIndexer } from '@ipld/car/indexer'`
|
|
33
|
-
* (`const { CarIndexer } = require('@ipld/car/indexer')`). Or
|
|
34
|
-
* `import { CarIndexer } from '@ipld/car'`
|
|
35
|
-
* (`const { CarIndexer } = require('@ipld/car')`). The former will likely
|
|
36
|
-
* result in smaller bundle sizes where this is important.
|
|
37
|
-
*
|
|
38
|
-
* @name CarIndexer
|
|
39
|
-
* @class
|
|
40
|
-
* @implements {RootsReader}
|
|
41
|
-
* @implements {AsyncIterable<BlockIndex>}
|
|
42
|
-
* @property {number} version The version number of the CAR referenced by this
|
|
43
|
-
* reader (should be `1`).
|
|
44
|
-
*/
|
|
45
|
-
export class CarIndexer {
|
|
46
|
-
/**
|
|
47
|
-
* @param {number} version
|
|
48
|
-
* @param {CID[]} roots
|
|
49
|
-
* @param {AsyncGenerator<BlockIndex>} iterator
|
|
50
|
-
*/
|
|
51
|
-
constructor (version, roots, iterator) {
|
|
52
|
-
this._version = version
|
|
53
|
-
this._roots = roots
|
|
54
|
-
this._iterator = iterator
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get version () {
|
|
58
|
-
return this._version
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get the list of roots defined by the CAR referenced by this indexer. May be
|
|
63
|
-
* zero or more `CID`s.
|
|
64
|
-
*
|
|
65
|
-
* @function
|
|
66
|
-
* @memberof CarIndexer
|
|
67
|
-
* @instance
|
|
68
|
-
* @async
|
|
69
|
-
* @returns {Promise<CID[]>}
|
|
70
|
-
*/
|
|
71
|
-
async getRoots () {
|
|
72
|
-
return this._roots
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @returns {AsyncIterator<BlockIndex>}
|
|
77
|
-
*/
|
|
78
|
-
[Symbol.asyncIterator] () {
|
|
79
|
-
return this._iterator
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Instantiate a {@link CarIndexer} from a `Uint8Array` blob. Only the header
|
|
84
|
-
* is decoded initially, the remainder is processed and emitted via the
|
|
85
|
-
* iterator as it is consumed.
|
|
86
|
-
*
|
|
87
|
-
* @async
|
|
88
|
-
* @static
|
|
89
|
-
* @memberof CarIndexer
|
|
90
|
-
* @param {Uint8Array} bytes
|
|
91
|
-
* @returns {Promise<CarIndexer>}
|
|
92
|
-
*/
|
|
93
|
-
static async fromBytes (bytes) {
|
|
94
|
-
if (!(bytes instanceof Uint8Array)) {
|
|
95
|
-
throw new TypeError('fromBytes() requires a Uint8Array')
|
|
96
|
-
}
|
|
97
|
-
return decodeIndexerComplete(bytesReader(bytes))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Instantiate a {@link CarIndexer} from a `AsyncIterable<Uint8Array>`,
|
|
102
|
-
* such as a [modern Node.js stream](https://nodejs.org/api/stream.html#stream_streams_compatibility_with_async_generators_and_async_iterators).
|
|
103
|
-
* is decoded initially, the remainder is processed and emitted via the
|
|
104
|
-
* iterator as it is consumed.
|
|
105
|
-
*
|
|
106
|
-
* @async
|
|
107
|
-
* @static
|
|
108
|
-
* @memberof CarIndexer
|
|
109
|
-
* @param {AsyncIterable<Uint8Array>} asyncIterable
|
|
110
|
-
* @returns {Promise<CarIndexer>}
|
|
111
|
-
*/
|
|
112
|
-
static async fromIterable (asyncIterable) {
|
|
113
|
-
if (!asyncIterable || !(typeof asyncIterable[Symbol.asyncIterator] === 'function')) {
|
|
114
|
-
throw new TypeError('fromIterable() requires an async iterable')
|
|
115
|
-
}
|
|
116
|
-
return decodeIndexerComplete(asyncIterableReader(asyncIterable))
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @private
|
|
122
|
-
* @param {BytesReader} reader
|
|
123
|
-
* @returns {Promise<CarIndexer>}
|
|
124
|
-
*/
|
|
125
|
-
async function decodeIndexerComplete (reader) {
|
|
126
|
-
const decoder = createDecoder(reader)
|
|
127
|
-
const { version, roots } = await decoder.header()
|
|
128
|
-
|
|
129
|
-
return new CarIndexer(version, roots, decoder.blocksIndex())
|
|
130
|
-
}
|