@fireproof/vendor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -109
- 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/promise-fs-opts.d.ts +0 -28
- package/src/@ipld/car/dist/src/promise-fs-opts.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 -40
- 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/promise-fs-opts.js +0 -46
- package/src/@ipld/car/src/reader-browser.js +0 -194
- package/src/@ipld/car/src/reader.js +0 -54
- package/src/@ipld/car/src/writer-browser.js +0 -250
- package/src/@ipld/car/src/writer.js +0 -81
- 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,310 +0,0 @@
|
|
|
1
|
-
// TODO: shift some of the bytes logic to bytes-utils so we can use Buffer
|
|
2
|
-
// where possible
|
|
3
|
-
|
|
4
|
-
import { Token, Type } from './token.js'
|
|
5
|
-
import { encodeUint } from './0uint.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {import('./bl.js').Bl} Bl
|
|
9
|
-
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
10
|
-
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const MINOR_FALSE = 20
|
|
14
|
-
const MINOR_TRUE = 21
|
|
15
|
-
const MINOR_NULL = 22
|
|
16
|
-
const MINOR_UNDEFINED = 23
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param {Uint8Array} _data
|
|
20
|
-
* @param {number} _pos
|
|
21
|
-
* @param {number} _minor
|
|
22
|
-
* @param {DecodeOptions} options
|
|
23
|
-
* @returns {Token}
|
|
24
|
-
*/
|
|
25
|
-
export function decodeUndefined (_data, _pos, _minor, options) {
|
|
26
|
-
if (options.allowUndefined === false) {
|
|
27
|
-
throw new Error(`${options.decodeErrPrefix} undefined values are not supported`)
|
|
28
|
-
} else if (options.coerceUndefinedToNull === true) {
|
|
29
|
-
return new Token(Type.null, null, 1)
|
|
30
|
-
}
|
|
31
|
-
return new Token(Type.undefined, undefined, 1)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @param {Uint8Array} _data
|
|
36
|
-
* @param {number} _pos
|
|
37
|
-
* @param {number} _minor
|
|
38
|
-
* @param {DecodeOptions} options
|
|
39
|
-
* @returns {Token}
|
|
40
|
-
*/
|
|
41
|
-
export function decodeBreak (_data, _pos, _minor, options) {
|
|
42
|
-
if (options.allowIndefinite === false) {
|
|
43
|
-
throw new Error(`${options.decodeErrPrefix} indefinite length items not allowed`)
|
|
44
|
-
}
|
|
45
|
-
return new Token(Type.break, undefined, 1)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @param {number} value
|
|
50
|
-
* @param {number} bytes
|
|
51
|
-
* @param {DecodeOptions} options
|
|
52
|
-
* @returns {Token}
|
|
53
|
-
*/
|
|
54
|
-
function createToken (value, bytes, options) {
|
|
55
|
-
if (options) {
|
|
56
|
-
if (options.allowNaN === false && Number.isNaN(value)) {
|
|
57
|
-
throw new Error(`${options.decodeErrPrefix} NaN values are not supported`)
|
|
58
|
-
}
|
|
59
|
-
if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) {
|
|
60
|
-
throw new Error(`${options.decodeErrPrefix} Infinity values are not supported`)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return new Token(Type.float, value, bytes)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @param {Uint8Array} data
|
|
68
|
-
* @param {number} pos
|
|
69
|
-
* @param {number} _minor
|
|
70
|
-
* @param {DecodeOptions} options
|
|
71
|
-
* @returns {Token}
|
|
72
|
-
*/
|
|
73
|
-
export function decodeFloat16 (data, pos, _minor, options) {
|
|
74
|
-
return createToken(readFloat16(data, pos + 1, options.decodeErrPrefix), 3, options)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param {Uint8Array} data
|
|
79
|
-
* @param {number} pos
|
|
80
|
-
* @param {number} _minor
|
|
81
|
-
* @param {DecodeOptions} options
|
|
82
|
-
* @returns {Token}
|
|
83
|
-
*/
|
|
84
|
-
export function decodeFloat32 (data, pos, _minor, options) {
|
|
85
|
-
return createToken(readFloat32(data, pos + 1, options.decodeErrPrefix), 5, options)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @param {Uint8Array} data
|
|
90
|
-
* @param {number} pos
|
|
91
|
-
* @param {number} _minor
|
|
92
|
-
* @param {DecodeOptions} options
|
|
93
|
-
* @returns {Token}
|
|
94
|
-
*/
|
|
95
|
-
export function decodeFloat64 (data, pos, _minor, options) {
|
|
96
|
-
return createToken(readFloat64(data, pos + 1, options.decodeErrPrefix), 9, options)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @param {Bl} buf
|
|
101
|
-
* @param {Token} token
|
|
102
|
-
* @param {EncodeOptions} options
|
|
103
|
-
*/
|
|
104
|
-
export function encodeFloat (buf, token, options) {
|
|
105
|
-
const float = token.value
|
|
106
|
-
|
|
107
|
-
if (float === false) {
|
|
108
|
-
buf.push([Type.float.majorEncoded | MINOR_FALSE])
|
|
109
|
-
} else if (float === true) {
|
|
110
|
-
buf.push([Type.float.majorEncoded | MINOR_TRUE])
|
|
111
|
-
} else if (float === null) {
|
|
112
|
-
buf.push([Type.float.majorEncoded | MINOR_NULL])
|
|
113
|
-
} else if (float === undefined) {
|
|
114
|
-
buf.push([Type.float.majorEncoded | MINOR_UNDEFINED])
|
|
115
|
-
} else {
|
|
116
|
-
let decoded
|
|
117
|
-
let success = false
|
|
118
|
-
if (!options || options.float64 !== true) {
|
|
119
|
-
encodeFloat16(float)
|
|
120
|
-
decoded = readFloat16(ui8a, 1, options.encodeErrPrefix)
|
|
121
|
-
if (float === decoded || Number.isNaN(float)) {
|
|
122
|
-
ui8a[0] = 0xf9
|
|
123
|
-
buf.push(ui8a.slice(0, 3))
|
|
124
|
-
success = true
|
|
125
|
-
} else {
|
|
126
|
-
encodeFloat32(float)
|
|
127
|
-
decoded = readFloat32(ui8a, 1, options.encodeErrPrefix)
|
|
128
|
-
if (float === decoded) {
|
|
129
|
-
ui8a[0] = 0xfa
|
|
130
|
-
buf.push(ui8a.slice(0, 5))
|
|
131
|
-
success = true
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (!success) {
|
|
136
|
-
encodeFloat64(float)
|
|
137
|
-
decoded = readFloat64(ui8a, 1, options.encodeErrPrefix)
|
|
138
|
-
ui8a[0] = 0xfb
|
|
139
|
-
buf.push(ui8a.slice(0, 9))
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @param {Token} token
|
|
146
|
-
* @param {EncodeOptions} options
|
|
147
|
-
* @returns {number}
|
|
148
|
-
*/
|
|
149
|
-
encodeFloat.encodedSize = function encodedSize (token, options) {
|
|
150
|
-
const float = token.value
|
|
151
|
-
|
|
152
|
-
if (float === false || float === true || float === null || float === undefined) {
|
|
153
|
-
return 1
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (!options || options.float64 !== true) {
|
|
157
|
-
encodeFloat16(float)
|
|
158
|
-
let decoded = readFloat16(ui8a, 1, options.encodeErrPrefix)
|
|
159
|
-
if (float === decoded || Number.isNaN(float)) {
|
|
160
|
-
return 3
|
|
161
|
-
}
|
|
162
|
-
encodeFloat32(float)
|
|
163
|
-
decoded = readFloat32(ui8a, 1, options.encodeErrPrefix)
|
|
164
|
-
if (float === decoded) {
|
|
165
|
-
return 5
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return 9
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const buffer = new ArrayBuffer(9)
|
|
172
|
-
const dataView = new DataView(buffer, 1)
|
|
173
|
-
const ui8a = new Uint8Array(buffer, 0)
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* @param {number} inp
|
|
177
|
-
*/
|
|
178
|
-
function encodeFloat16 (inp) {
|
|
179
|
-
if (inp === Infinity) {
|
|
180
|
-
dataView.setUint16(0, 0x7c00, false)
|
|
181
|
-
} else if (inp === -Infinity) {
|
|
182
|
-
dataView.setUint16(0, 0xfc00, false)
|
|
183
|
-
} else if (Number.isNaN(inp)) {
|
|
184
|
-
dataView.setUint16(0, 0x7e00, false)
|
|
185
|
-
} else {
|
|
186
|
-
dataView.setFloat32(0, inp)
|
|
187
|
-
const valu32 = dataView.getUint32(0)
|
|
188
|
-
const exponent = (valu32 & 0x7f800000) >> 23
|
|
189
|
-
const mantissa = valu32 & 0x7fffff
|
|
190
|
-
|
|
191
|
-
/* c8 ignore next 6 */
|
|
192
|
-
if (exponent === 0xff) {
|
|
193
|
-
// too big, Infinity, but this should be hard (impossible?) to trigger
|
|
194
|
-
dataView.setUint16(0, 0x7c00, false)
|
|
195
|
-
} else if (exponent === 0x00) {
|
|
196
|
-
// 0.0, -0.0 and subnormals, shouldn't be possible to get here because 0.0 should be counted as an int
|
|
197
|
-
dataView.setUint16(0, ((inp & 0x80000000) >> 16) | (mantissa >> 13), false)
|
|
198
|
-
} else { // standard numbers
|
|
199
|
-
// chunks of logic here borrowed from https://github.com/PJK/libcbor/blob/c78f437182533e3efa8d963ff4b945bb635c2284/src/cbor/encoding.c#L127
|
|
200
|
-
const logicalExponent = exponent - 127
|
|
201
|
-
// Now we know that 2^exponent <= 0 logically
|
|
202
|
-
/* c8 ignore next 6 */
|
|
203
|
-
if (logicalExponent < -24) {
|
|
204
|
-
/* No unambiguous representation exists, this float is not a half float
|
|
205
|
-
and is too small to be represented using a half, round off to zero.
|
|
206
|
-
Consistent with the reference implementation. */
|
|
207
|
-
// should be difficult (impossible?) to get here in JS
|
|
208
|
-
dataView.setUint16(0, 0)
|
|
209
|
-
} else if (logicalExponent < -14) {
|
|
210
|
-
/* Offset the remaining decimal places by shifting the significand, the
|
|
211
|
-
value is lost. This is an implementation decision that works around the
|
|
212
|
-
absence of standard half-float in the language. */
|
|
213
|
-
dataView.setUint16(0, ((valu32 & 0x80000000) >> 16) | /* sign bit */ (1 << (24 + logicalExponent)), false)
|
|
214
|
-
} else {
|
|
215
|
-
dataView.setUint16(0, ((valu32 & 0x80000000) >> 16) | ((logicalExponent + 15) << 10) | (mantissa >> 13), false)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @param {Uint8Array} ui8a
|
|
223
|
-
* @param {number} pos
|
|
224
|
-
* @param {string} encodeErrPrefix
|
|
225
|
-
* @returns {number}
|
|
226
|
-
*/
|
|
227
|
-
function readFloat16 (ui8a, pos, encodeErrPrefix) {
|
|
228
|
-
if (ui8a.length - pos < 2) {
|
|
229
|
-
throw new Error(`${encodeErrPrefix} not enough data for float16`)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const half = (ui8a[pos] << 8) + ui8a[pos + 1]
|
|
233
|
-
if (half === 0x7c00) {
|
|
234
|
-
return Infinity
|
|
235
|
-
}
|
|
236
|
-
if (half === 0xfc00) {
|
|
237
|
-
return -Infinity
|
|
238
|
-
}
|
|
239
|
-
if (half === 0x7e00) {
|
|
240
|
-
return NaN
|
|
241
|
-
}
|
|
242
|
-
const exp = (half >> 10) & 0x1f
|
|
243
|
-
const mant = half & 0x3ff
|
|
244
|
-
let val
|
|
245
|
-
if (exp === 0) {
|
|
246
|
-
val = mant * (2 ** -24)
|
|
247
|
-
} else if (exp !== 31) {
|
|
248
|
-
val = (mant + 1024) * (2 ** (exp - 25))
|
|
249
|
-
/* c8 ignore next 4 */
|
|
250
|
-
} else {
|
|
251
|
-
// may not be possible to get here
|
|
252
|
-
val = mant === 0 ? Infinity : NaN
|
|
253
|
-
}
|
|
254
|
-
return (half & 0x8000) ? -val : val
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* @param {number} inp
|
|
259
|
-
*/
|
|
260
|
-
function encodeFloat32 (inp) {
|
|
261
|
-
dataView.setFloat32(0, inp, false)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* @param {Uint8Array} ui8a
|
|
266
|
-
* @param {number} pos
|
|
267
|
-
* @param {string} encodeErrPrefix
|
|
268
|
-
* @returns {number}
|
|
269
|
-
*/
|
|
270
|
-
function readFloat32 (ui8a, pos, encodeErrPrefix) {
|
|
271
|
-
if (ui8a.length - pos < 4) {
|
|
272
|
-
throw new Error(`${encodeErrPrefix} not enough data for float32`)
|
|
273
|
-
}
|
|
274
|
-
const offset = (ui8a.byteOffset || 0) + pos
|
|
275
|
-
return new DataView(ui8a.buffer, offset, 4).getFloat32(0, false)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @param {number} inp
|
|
280
|
-
*/
|
|
281
|
-
function encodeFloat64 (inp) {
|
|
282
|
-
dataView.setFloat64(0, inp, false)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* @param {Uint8Array} ui8a
|
|
287
|
-
* @param {number} pos
|
|
288
|
-
* @param {string} encodeErrPrefix
|
|
289
|
-
* @returns {number}
|
|
290
|
-
*/
|
|
291
|
-
function readFloat64 (ui8a, pos, encodeErrPrefix) {
|
|
292
|
-
if (ui8a.length - pos < 8) {
|
|
293
|
-
throw new Error(`${encodeErrPrefix} not enough data for float64`)
|
|
294
|
-
}
|
|
295
|
-
const offset = (ui8a.byteOffset || 0) + pos
|
|
296
|
-
return new DataView(ui8a.buffer, offset, 8).getFloat64(0, false)
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* @param {Token} _tok1
|
|
301
|
-
* @param {Token} _tok2
|
|
302
|
-
* @returns {number}
|
|
303
|
-
*/
|
|
304
|
-
encodeFloat.compareTokens = encodeUint.compareTokens
|
|
305
|
-
/*
|
|
306
|
-
encodeFloat.compareTokens = function compareTokens (_tok1, _tok2) {
|
|
307
|
-
return _tok1
|
|
308
|
-
throw new Error(`${encodeErrPrefix} cannot use floats as map keys`)
|
|
309
|
-
}
|
|
310
|
-
*/
|
package/src/cborg/utils/bl.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bl is a list of byte chunks, similar to https://github.com/rvagg/bl but for
|
|
3
|
-
* writing rather than reading.
|
|
4
|
-
* A Bl object accepts set() operations for individual bytes and copyTo() for
|
|
5
|
-
* inserting byte arrays. These write operations don't automatically increment
|
|
6
|
-
* the internal cursor so its "length" won't be changed. Instead, increment()
|
|
7
|
-
* must be called to extend its length to cover the inserted data.
|
|
8
|
-
* The toBytes() call will convert all internal memory to a single Uint8Array of
|
|
9
|
-
* the correct length, truncating any data that is stored but hasn't been
|
|
10
|
-
* included by an increment().
|
|
11
|
-
* get() can retrieve a single byte.
|
|
12
|
-
* All operations (except toBytes()) take an "offset" argument that will perform
|
|
13
|
-
* the write at the offset _from the current cursor_. For most operations this
|
|
14
|
-
* will be `0` to write at the current cursor position but it can be ahead of
|
|
15
|
-
* the current cursor. Negative offsets probably work but are untested.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
// TODO: ipjs doesn't support this, only for test files: https://github.com/mikeal/ipjs/blob/master/src/package/testFile.js#L39
|
|
19
|
-
import { alloc, concat, slice } from "@fireproof/vendor/cborg/utils"
|
|
20
|
-
|
|
21
|
-
// the ts-ignores in this file are almost all for the `Uint8Array|number[]` duality that exists
|
|
22
|
-
// for perf reasons. Consider better approaches to this or removing it entirely, it is quite
|
|
23
|
-
// risky because of some assumptions about small chunks === number[] and everything else === Uint8Array.
|
|
24
|
-
|
|
25
|
-
const defaultChunkSize = 256
|
|
26
|
-
|
|
27
|
-
export class Bl {
|
|
28
|
-
/**
|
|
29
|
-
* @param {number} [chunkSize]
|
|
30
|
-
*/
|
|
31
|
-
constructor (chunkSize = defaultChunkSize) {
|
|
32
|
-
this.chunkSize = chunkSize
|
|
33
|
-
/** @type {number} */
|
|
34
|
-
this.cursor = 0
|
|
35
|
-
/** @type {number} */
|
|
36
|
-
this.maxCursor = -1
|
|
37
|
-
/** @type {(Uint8Array|number[])[]} */
|
|
38
|
-
this.chunks = []
|
|
39
|
-
// keep the first chunk around if we can to save allocations for future encodes
|
|
40
|
-
/** @type {Uint8Array|number[]|null} */
|
|
41
|
-
this._initReuseChunk = null
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
reset () {
|
|
45
|
-
this.cursor = 0
|
|
46
|
-
this.maxCursor = -1
|
|
47
|
-
if (this.chunks.length) {
|
|
48
|
-
this.chunks = []
|
|
49
|
-
}
|
|
50
|
-
if (this._initReuseChunk !== null) {
|
|
51
|
-
this.chunks.push(this._initReuseChunk)
|
|
52
|
-
this.maxCursor = this._initReuseChunk.length - 1
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {Uint8Array|number[]} bytes
|
|
58
|
-
*/
|
|
59
|
-
push (bytes) {
|
|
60
|
-
let topChunk = this.chunks[this.chunks.length - 1]
|
|
61
|
-
const newMax = this.cursor + bytes.length
|
|
62
|
-
if (newMax <= this.maxCursor + 1) {
|
|
63
|
-
// we have at least one chunk and we can fit these bytes into that chunk
|
|
64
|
-
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
topChunk.set(bytes, chunkPos)
|
|
67
|
-
} else {
|
|
68
|
-
// can't fit it in
|
|
69
|
-
if (topChunk) {
|
|
70
|
-
// trip the last chunk to `cursor` if we need to
|
|
71
|
-
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1
|
|
72
|
-
if (chunkPos < topChunk.length) {
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos)
|
|
75
|
-
this.maxCursor = this.cursor - 1
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (bytes.length < 64 && bytes.length < this.chunkSize) {
|
|
79
|
-
// make a new chunk and copy the new one into it
|
|
80
|
-
topChunk = alloc(this.chunkSize)
|
|
81
|
-
this.chunks.push(topChunk)
|
|
82
|
-
this.maxCursor += topChunk.length
|
|
83
|
-
if (this._initReuseChunk === null) {
|
|
84
|
-
this._initReuseChunk = topChunk
|
|
85
|
-
}
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
topChunk.set(bytes, 0)
|
|
88
|
-
} else {
|
|
89
|
-
// push the new bytes in as its own chunk
|
|
90
|
-
this.chunks.push(bytes)
|
|
91
|
-
this.maxCursor += bytes.length
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
this.cursor += bytes.length
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @param {boolean} [reset]
|
|
99
|
-
* @returns {Uint8Array}
|
|
100
|
-
*/
|
|
101
|
-
toBytes (reset = false) {
|
|
102
|
-
let byts
|
|
103
|
-
if (this.chunks.length === 1) {
|
|
104
|
-
const chunk = this.chunks[0]
|
|
105
|
-
if (reset && this.cursor > chunk.length / 2) {
|
|
106
|
-
/* c8 ignore next 2 */
|
|
107
|
-
// @ts-ignore
|
|
108
|
-
byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor)
|
|
109
|
-
this._initReuseChunk = null
|
|
110
|
-
this.chunks = []
|
|
111
|
-
} else {
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
byts = slice(chunk, 0, this.cursor)
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
byts = concat(this.chunks, this.cursor)
|
|
118
|
-
}
|
|
119
|
-
if (reset) {
|
|
120
|
-
this.reset()
|
|
121
|
-
}
|
|
122
|
-
return byts
|
|
123
|
-
}
|
|
124
|
-
}
|