@fireproof/vendor 0.0.0-smoke
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 +29 -0
- package/patched/@ipld/dag-json/.github/dependabot.yml +11 -0
- package/patched/@ipld/dag-json/.github/workflows/js-test-and-release.yml +28 -0
- package/patched/@ipld/dag-json/CHANGELOG.md +202 -0
- package/patched/@ipld/dag-json/LICENSE +4 -0
- package/patched/@ipld/dag-json/LICENSE-APACHE +5 -0
- package/patched/@ipld/dag-json/LICENSE-MIT +19 -0
- package/patched/@ipld/dag-json/README.md +58 -0
- package/patched/@ipld/dag-json/ipld-dag-json-10.2.3.tgz +0 -0
- package/patched/@ipld/dag-json/package.json +173 -0
- package/patched/@ipld/dag-json/src/index.js +291 -0
- package/patched/@ipld/dag-json/test/test-basics.spec.js +290 -0
- package/patched/@ipld/dag-json/test/ts-use/package.json +11 -0
- package/patched/@ipld/dag-json/test/ts-use/src/main.ts +54 -0
- package/patched/@ipld/dag-json/test/ts-use/tsconfig.json +9 -0
- package/patched/@ipld/dag-json/tsconfig.json +14 -0
- package/patched/cborg/.github/dependabot.yml +16 -0
- package/patched/cborg/.github/workflows/test-and-release.yml +52 -0
- package/patched/cborg/CHANGELOG.md +513 -0
- package/patched/cborg/LICENSE +13 -0
- package/patched/cborg/README.md +515 -0
- package/patched/cborg/bench/bench.js +117 -0
- package/patched/cborg/bench/json.js +124 -0
- package/patched/cborg/bench/package.json +8 -0
- package/patched/cborg/cborg-4.2.7.tgz +0 -0
- package/patched/cborg/cborg.js +31 -0
- package/patched/cborg/example-bytestrings.js +180 -0
- package/patched/cborg/example-json.js +6 -0
- package/patched/cborg/example.js +5 -0
- package/patched/cborg/interface.ts +56 -0
- package/patched/cborg/lib/0uint.js +227 -0
- package/patched/cborg/lib/1negint.js +111 -0
- package/patched/cborg/lib/2bytes.js +133 -0
- package/patched/cborg/lib/3string.js +90 -0
- package/patched/cborg/lib/4array.js +113 -0
- package/patched/cborg/lib/5map.js +113 -0
- package/patched/cborg/lib/6tag.js +80 -0
- package/patched/cborg/lib/7float.js +308 -0
- package/patched/cborg/lib/bin.js +189 -0
- package/patched/cborg/lib/bl.js +124 -0
- package/patched/cborg/lib/byte-utils.js +417 -0
- package/patched/cborg/lib/common.js +27 -0
- package/patched/cborg/lib/decode.js +209 -0
- package/patched/cborg/lib/diagnostic.js +156 -0
- package/patched/cborg/lib/diagnostic_test.js +117 -0
- package/patched/cborg/lib/encode.js +464 -0
- package/patched/cborg/lib/is.js +106 -0
- package/patched/cborg/lib/json/decode.js +462 -0
- package/patched/cborg/lib/json/encode.js +299 -0
- package/patched/cborg/lib/json/json.js +4 -0
- package/patched/cborg/lib/jump.js +209 -0
- package/patched/cborg/lib/length.js +61 -0
- package/patched/cborg/lib/token.js +76 -0
- package/patched/cborg/package.json +169 -0
- package/patched/cborg/pnpm-lock.yaml +6096 -0
- package/patched/cborg/taglib.js +73 -0
- package/patched/cborg/test/appendix_a.js +647 -0
- package/patched/cborg/test/common.js +18 -0
- package/patched/cborg/test/node-test-bin.js +402 -0
- package/patched/cborg/test/noop-bin-test.js +3 -0
- package/patched/cborg/test/test-0uint.js +103 -0
- package/patched/cborg/test/test-1negint.js +96 -0
- package/patched/cborg/test/test-2bytes.js +198 -0
- package/patched/cborg/test/test-3string.js +136 -0
- package/patched/cborg/test/test-4array.js +93 -0
- package/patched/cborg/test/test-5map.js +284 -0
- package/patched/cborg/test/test-6tag.js +85 -0
- package/patched/cborg/test/test-7float.js +131 -0
- package/patched/cborg/test/test-bl.js +37 -0
- package/patched/cborg/test/test-cbor-vectors.js +107 -0
- package/patched/cborg/test/test-decode-errors.js +65 -0
- package/patched/cborg/test/test-fuzz.js +42 -0
- package/patched/cborg/test/test-json.js +219 -0
- package/patched/cborg/test/test-length.js +65 -0
- package/patched/cborg/test/test-partial.js +111 -0
- package/patched/cborg/tsconfig.json +45 -0
- package/patched/cborg/types/cborg.d.ts +28 -0
- package/patched/cborg/types/cborg.d.ts.map +1 -0
- package/patched/cborg/types/example.d.ts +2 -0
- package/patched/cborg/types/example.d.ts.map +1 -0
- package/patched/cborg/types/interface.d.ts +47 -0
- package/patched/cborg/types/interface.d.ts.map +1 -0
- package/patched/cborg/types/lib/0uint.d.ts +100 -0
- package/patched/cborg/types/lib/0uint.d.ts.map +1 -0
- package/patched/cborg/types/lib/1negint.d.ts +58 -0
- package/patched/cborg/types/lib/1negint.d.ts.map +1 -0
- package/patched/cborg/types/lib/2bytes.d.ts +68 -0
- package/patched/cborg/types/lib/2bytes.d.ts.map +1 -0
- package/patched/cborg/types/lib/3string.d.ts +46 -0
- package/patched/cborg/types/lib/3string.d.ts.map +1 -0
- package/patched/cborg/types/lib/4array.d.ts +65 -0
- package/patched/cborg/types/lib/4array.d.ts.map +1 -0
- package/patched/cborg/types/lib/5map.d.ts +65 -0
- package/patched/cborg/types/lib/5map.d.ts.map +1 -0
- package/patched/cborg/types/lib/6tag.d.ts +61 -0
- package/patched/cborg/types/lib/6tag.d.ts.map +1 -0
- package/patched/cborg/types/lib/7float.d.ts +60 -0
- package/patched/cborg/types/lib/7float.d.ts.map +1 -0
- package/patched/cborg/types/lib/bin.d.ts +4 -0
- package/patched/cborg/types/lib/bin.d.ts.map +1 -0
- package/patched/cborg/types/lib/bl.d.ts +26 -0
- package/patched/cborg/types/lib/bl.d.ts.map +1 -0
- package/patched/cborg/types/lib/byte-utils.d.ts +53 -0
- package/patched/cborg/types/lib/byte-utils.d.ts.map +1 -0
- package/patched/cborg/types/lib/common.d.ts +10 -0
- package/patched/cborg/types/lib/common.d.ts.map +1 -0
- package/patched/cborg/types/lib/decode.d.ts +41 -0
- package/patched/cborg/types/lib/decode.d.ts.map +1 -0
- package/patched/cborg/types/lib/diagnostic.d.ts +12 -0
- package/patched/cborg/types/lib/diagnostic.d.ts.map +1 -0
- package/patched/cborg/types/lib/diagnostic_test.d.ts +2 -0
- package/patched/cborg/types/lib/diagnostic_test.d.ts.map +1 -0
- package/patched/cborg/types/lib/encode.d.ts +50 -0
- package/patched/cborg/types/lib/encode.d.ts.map +1 -0
- package/patched/cborg/types/lib/is.d.ts +6 -0
- package/patched/cborg/types/lib/is.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/decode.d.ts +67 -0
- package/patched/cborg/types/lib/json/decode.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/encode.d.ts +11 -0
- package/patched/cborg/types/lib/json/encode.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/forward-cborg.d.ts +6 -0
- package/patched/cborg/types/lib/json/forward-cborg.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/json.d.ts +6 -0
- package/patched/cborg/types/lib/json/json.d.ts.map +1 -0
- package/patched/cborg/types/lib/jump.d.ts +12 -0
- package/patched/cborg/types/lib/jump.d.ts.map +1 -0
- package/patched/cborg/types/lib/length.d.ts +27 -0
- package/patched/cborg/types/lib/length.d.ts.map +1 -0
- package/patched/cborg/types/lib/token.d.ts +59 -0
- package/patched/cborg/types/lib/token.d.ts.map +1 -0
- package/patched/cborg/types/taglib.d.ts +18 -0
- package/patched/cborg/types/taglib.d.ts.map +1 -0
- package/patched/cborg/types/tsconfig.tsbuildinfo +1 -0
- package/src/@ipld/car/car/LICENSE +4 -0
- package/src/@ipld/car/car/README.md +1078 -0
- package/src/@ipld/car/car/dist/index.min.js +5 -0
- package/src/@ipld/car/car/dist/src/api.d.ts +72 -0
- package/src/@ipld/car/car/dist/src/api.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-decoder.d.ts +67 -0
- package/src/@ipld/car/car/dist/src/buffer-decoder.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-reader-browser.d.ts +116 -0
- package/src/@ipld/car/car/dist/src/buffer-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-reader.d.ts +31 -0
- package/src/@ipld/car/car/dist/src/buffer-reader.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-writer.d.ts +86 -0
- package/src/@ipld/car/car/dist/src/buffer-writer.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/coding.d.ts +49 -0
- package/src/@ipld/car/car/dist/src/coding.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/decoder-common.d.ts +43 -0
- package/src/@ipld/car/car/dist/src/decoder-common.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/decoder.d.ts +87 -0
- package/src/@ipld/car/car/dist/src/decoder.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/encoder.d.ts +17 -0
- package/src/@ipld/car/car/dist/src/encoder.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/header-validator.d.ts +5 -0
- package/src/@ipld/car/car/dist/src/header-validator.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/index-browser.d.ts +10 -0
- package/src/@ipld/car/car/dist/src/index-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/index.d.ts +11 -0
- package/src/@ipld/car/car/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/indexed-reader-browser.d.ts +5 -0
- package/src/@ipld/car/car/dist/src/indexed-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/indexed-reader.d.ts +152 -0
- package/src/@ipld/car/car/dist/src/indexed-reader.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/indexer.d.ts +95 -0
- package/src/@ipld/car/car/dist/src/indexer.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/iterator-channel.d.ts +7 -0
- package/src/@ipld/car/car/dist/src/iterator-channel.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/iterator.d.ts +174 -0
- package/src/@ipld/car/car/dist/src/iterator.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/reader-browser.d.ts +151 -0
- package/src/@ipld/car/car/dist/src/reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/reader.d.ts +35 -0
- package/src/@ipld/car/car/dist/src/reader.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/writer-browser.d.ts +155 -0
- package/src/@ipld/car/car/dist/src/writer-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/writer.d.ts +45 -0
- package/src/@ipld/car/car/dist/src/writer.d.ts.map +1 -0
- package/src/@ipld/car/car/node_modules/.bin/cborg +17 -0
- package/src/@ipld/car/car/package.json +235 -0
- package/src/@ipld/car/car/src/api.ts +90 -0
- package/src/@ipld/car/car/src/buffer-decoder.js +213 -0
- package/src/@ipld/car/car/src/buffer-reader-browser.js +144 -0
- package/src/@ipld/car/car/src/buffer-reader.js +51 -0
- package/src/@ipld/car/car/src/buffer-writer.js +286 -0
- package/src/@ipld/car/car/src/coding.ts +68 -0
- package/src/@ipld/car/car/src/decoder-common.js +82 -0
- package/src/@ipld/car/car/src/decoder.js +347 -0
- package/src/@ipld/car/car/src/encoder.js +76 -0
- package/src/@ipld/car/car/src/header-validator.js +214 -0
- package/src/@ipld/car/car/src/header.ipldsch +18 -0
- package/src/@ipld/car/car/src/index-browser.js +18 -0
- package/src/@ipld/car/car/src/index.js +21 -0
- package/src/@ipld/car/car/src/indexed-reader-browser.js +7 -0
- package/src/@ipld/car/car/src/indexed-reader.js +211 -0
- package/src/@ipld/car/car/src/indexer.js +130 -0
- package/src/@ipld/car/car/src/iterator-channel.js +91 -0
- package/src/@ipld/car/car/src/iterator.js +267 -0
- package/src/@ipld/car/car/src/reader-browser.js +194 -0
- package/src/@ipld/car/car/src/reader.js +56 -0
- package/src/@ipld/car/car/src/writer-browser.js +250 -0
- package/src/@ipld/car/car/src/writer.js +84 -0
- package/src/@ipld/dag-cbor/dag-cbor/LICENSE +4 -0
- package/src/@ipld/dag-cbor/dag-cbor/README.md +80 -0
- package/src/@ipld/dag-cbor/dag-cbor/dist/index.min.js +3 -0
- package/src/@ipld/dag-cbor/dag-cbor/dist/src/index.d.ts +67 -0
- package/src/@ipld/dag-cbor/dag-cbor/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-cbor/dag-cbor/node_modules/.bin/cborg +17 -0
- package/src/@ipld/dag-cbor/dag-cbor/package.json +171 -0
- package/src/@ipld/dag-cbor/dag-cbor/src/index.js +147 -0
- package/src/@ipld/dag-json/dag-json/LICENSE +4 -0
- package/src/@ipld/dag-json/dag-json/README.md +58 -0
- package/src/@ipld/dag-json/dag-json/dist/index.min.js +3 -0
- package/src/@ipld/dag-json/dag-json/dist/src/index.d.ts +12 -0
- package/src/@ipld/dag-json/dag-json/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-json/dag-json/node_modules/.bin/cborg +17 -0
- package/src/@ipld/dag-json/dag-json/package.json +173 -0
- package/src/@ipld/dag-json/dag-json/src/index.js +291 -0
- package/src/@web3-storage/pail/pail/LICENSE.md +232 -0
- package/src/@web3-storage/pail/pail/README.md +84 -0
- package/src/@web3-storage/pail/pail/cli.js +218 -0
- package/src/@web3-storage/pail/pail/dist/src/api.d.ts +59 -0
- package/src/@web3-storage/pail/pail/dist/src/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/api.d.ts +31 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/index.d.ts +75 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/shard.d.ts +3 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/shard.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/block.d.ts +35 -0
- package/src/@web3-storage/pail/pail/dist/src/block.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/api.d.ts +10 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/index.d.ts +48 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/api.d.ts +26 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/api.d.ts +11 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/index.d.ts +5 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/index.d.ts +9 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/diff.d.ts +13 -0
- package/src/@web3-storage/pail/pail/dist/src/diff.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/index.d.ts +10 -0
- package/src/@web3-storage/pail/pail/dist/src/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/merge.d.ts +5 -0
- package/src/@web3-storage/pail/pail/dist/src/merge.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/shard.d.ts +43 -0
- package/src/@web3-storage/pail/pail/dist/src/shard.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/tsconfig.tsbuildinfo +1 -0
- package/src/@web3-storage/pail/pail/node_modules/.bin/pail +17 -0
- package/src/@web3-storage/pail/pail/package.json +173 -0
- package/src/@web3-storage/pail/pail/src/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/api.ts +90 -0
- package/src/@web3-storage/pail/pail/src/batch/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/batch/api.ts +59 -0
- package/src/@web3-storage/pail/pail/src/batch/index.js +258 -0
- package/src/@web3-storage/pail/pail/src/batch/shard.js +13 -0
- package/src/@web3-storage/pail/pail/src/block.js +75 -0
- package/src/@web3-storage/pail/pail/src/clock/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/clock/api.ts +12 -0
- package/src/@web3-storage/pail/pail/src/clock/index.js +182 -0
- package/src/@web3-storage/pail/pail/src/crdt/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/crdt/api.ts +33 -0
- package/src/@web3-storage/pail/pail/src/crdt/batch/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/crdt/batch/api.ts +30 -0
- package/src/@web3-storage/pail/pail/src/crdt/batch/index.js +155 -0
- package/src/@web3-storage/pail/pail/src/crdt/index.js +354 -0
- package/src/@web3-storage/pail/pail/src/diff.js +151 -0
- package/src/@web3-storage/pail/pail/src/index.js +406 -0
- package/src/@web3-storage/pail/pail/src/merge.js +43 -0
- package/src/@web3-storage/pail/pail/src/shard.js +180 -0
- package/src/cborg/cborg/.github/dependabot.yml +16 -0
- package/src/cborg/cborg/.github/workflows/test-and-release.yml +52 -0
- package/src/cborg/cborg/CHANGELOG.md +513 -0
- package/src/cborg/cborg/LICENSE +13 -0
- package/src/cborg/cborg/README.md +515 -0
- package/src/cborg/cborg/bench/bench.js +117 -0
- package/src/cborg/cborg/bench/json.js +124 -0
- package/src/cborg/cborg/bench/package.json +8 -0
- package/src/cborg/cborg/cborg.js +31 -0
- package/src/cborg/cborg/example-bytestrings.js +180 -0
- package/src/cborg/cborg/example-json.js +6 -0
- package/src/cborg/cborg/example.js +5 -0
- package/src/cborg/cborg/interface.ts +56 -0
- package/src/cborg/cborg/lib/0uint.js +227 -0
- package/src/cborg/cborg/lib/1negint.js +111 -0
- package/src/cborg/cborg/lib/2bytes.js +133 -0
- package/src/cborg/cborg/lib/3string.js +90 -0
- package/src/cborg/cborg/lib/4array.js +113 -0
- package/src/cborg/cborg/lib/5map.js +113 -0
- package/src/cborg/cborg/lib/6tag.js +80 -0
- package/src/cborg/cborg/lib/7float.js +308 -0
- package/src/cborg/cborg/lib/bin.js +189 -0
- package/src/cborg/cborg/lib/bl.js +124 -0
- package/src/cborg/cborg/lib/byte-utils.js +417 -0
- package/src/cborg/cborg/lib/common.js +27 -0
- package/src/cborg/cborg/lib/decode.js +209 -0
- package/src/cborg/cborg/lib/diagnostic.js +156 -0
- package/src/cborg/cborg/lib/diagnostic_test.js +117 -0
- package/src/cborg/cborg/lib/encode.js +464 -0
- package/src/cborg/cborg/lib/is.js +106 -0
- package/src/cborg/cborg/lib/json/decode.js +462 -0
- package/src/cborg/cborg/lib/json/encode.js +299 -0
- package/src/cborg/cborg/lib/json/json.js +4 -0
- package/src/cborg/cborg/lib/jump.js +209 -0
- package/src/cborg/cborg/lib/length.js +61 -0
- package/src/cborg/cborg/lib/token.js +76 -0
- package/src/cborg/cborg/node_modules/.bin/cborg +17 -0
- package/src/cborg/cborg/package.json +168 -0
- package/src/cborg/cborg/taglib.js +73 -0
- package/src/cborg/cborg/test/appendix_a.js +647 -0
- package/src/cborg/cborg/test/common.js +18 -0
- package/src/cborg/cborg/test/node-test-bin.js +402 -0
- package/src/cborg/cborg/test/noop-bin-test.js +3 -0
- package/src/cborg/cborg/test/test-0uint.js +103 -0
- package/src/cborg/cborg/test/test-1negint.js +96 -0
- package/src/cborg/cborg/test/test-2bytes.js +198 -0
- package/src/cborg/cborg/test/test-3string.js +136 -0
- package/src/cborg/cborg/test/test-4array.js +93 -0
- package/src/cborg/cborg/test/test-5map.js +284 -0
- package/src/cborg/cborg/test/test-6tag.js +85 -0
- package/src/cborg/cborg/test/test-7float.js +131 -0
- package/src/cborg/cborg/test/test-bl.js +37 -0
- package/src/cborg/cborg/test/test-cbor-vectors.js +107 -0
- package/src/cborg/cborg/test/test-decode-errors.js +65 -0
- package/src/cborg/cborg/test/test-fuzz.js +42 -0
- package/src/cborg/cborg/test/test-json.js +219 -0
- package/src/cborg/cborg/test/test-length.js +65 -0
- package/src/cborg/cborg/test/test-partial.js +111 -0
- package/src/cborg/cborg/tsconfig.json +45 -0
- package/src/cborg/cborg/types/cborg.d.ts +28 -0
- package/src/cborg/cborg/types/cborg.d.ts.map +1 -0
- package/src/cborg/cborg/types/example.d.ts +2 -0
- package/src/cborg/cborg/types/example.d.ts.map +1 -0
- package/src/cborg/cborg/types/interface.d.ts +47 -0
- package/src/cborg/cborg/types/interface.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/0uint.d.ts +100 -0
- package/src/cborg/cborg/types/lib/0uint.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/1negint.d.ts +58 -0
- package/src/cborg/cborg/types/lib/1negint.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/2bytes.d.ts +68 -0
- package/src/cborg/cborg/types/lib/2bytes.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/3string.d.ts +46 -0
- package/src/cborg/cborg/types/lib/3string.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/4array.d.ts +65 -0
- package/src/cborg/cborg/types/lib/4array.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/5map.d.ts +65 -0
- package/src/cborg/cborg/types/lib/5map.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/6tag.d.ts +61 -0
- package/src/cborg/cborg/types/lib/6tag.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/7float.d.ts +60 -0
- package/src/cborg/cborg/types/lib/7float.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/bin.d.ts +4 -0
- package/src/cborg/cborg/types/lib/bin.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/bl.d.ts +26 -0
- package/src/cborg/cborg/types/lib/bl.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/byte-utils.d.ts +53 -0
- package/src/cborg/cborg/types/lib/byte-utils.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/common.d.ts +10 -0
- package/src/cborg/cborg/types/lib/common.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/decode.d.ts +41 -0
- package/src/cborg/cborg/types/lib/decode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/diagnostic.d.ts +12 -0
- package/src/cborg/cborg/types/lib/diagnostic.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/diagnostic_test.d.ts +2 -0
- package/src/cborg/cborg/types/lib/diagnostic_test.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/encode.d.ts +50 -0
- package/src/cborg/cborg/types/lib/encode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/is.d.ts +6 -0
- package/src/cborg/cborg/types/lib/is.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/decode.d.ts +67 -0
- package/src/cborg/cborg/types/lib/json/decode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/encode.d.ts +11 -0
- package/src/cborg/cborg/types/lib/json/encode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/forward-cborg.d.ts +6 -0
- package/src/cborg/cborg/types/lib/json/forward-cborg.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/json.d.ts +6 -0
- package/src/cborg/cborg/types/lib/json/json.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/jump.d.ts +12 -0
- package/src/cborg/cborg/types/lib/jump.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/length.d.ts +27 -0
- package/src/cborg/cborg/types/lib/length.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/token.d.ts +59 -0
- package/src/cborg/cborg/types/lib/token.d.ts.map +1 -0
- package/src/cborg/cborg/types/taglib.d.ts +18 -0
- package/src/cborg/cborg/types/taglib.d.ts.map +1 -0
- package/src/cborg/cborg/types/tsconfig.tsbuildinfo +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/LICENSE +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/README.md +105 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/index.min.js +3 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.d.ts +57 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.js +73 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.d.ts +355 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.js +197 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +9 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +9 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +38 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.js +30 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.js +9 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +37 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +29 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +153 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +59 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +25 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +104 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +3 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +20 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +116 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +57 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +30 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/typedoc-urls.json +58 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/package.json +180 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/errors.ts +87 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/index.ts +498 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +12 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +12 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/identity.ts +49 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/index.ts +35 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/json.ts +12 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/raw.ts +49 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +39 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +198 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +76 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +37 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +121 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +24 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +149 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +62 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +38 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// Use Uint8Array directly in the browser, use Buffer in Node.js but don't
|
|
2
|
+
// speak its name directly to avoid bundlers pulling in the `Buffer` polyfill
|
|
3
|
+
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
export const useBuffer = globalThis.process &&
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
!globalThis.process.browser &&
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
globalThis.Buffer &&
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
typeof globalThis.Buffer.isBuffer === 'function'
|
|
12
|
+
|
|
13
|
+
const textDecoder = new TextDecoder()
|
|
14
|
+
const textEncoder = new TextEncoder()
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Uint8Array} buf
|
|
18
|
+
* @returns {boolean}
|
|
19
|
+
*/
|
|
20
|
+
function isBuffer (buf) {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
return useBuffer && globalThis.Buffer.isBuffer(buf)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Uint8Array|number[]} buf
|
|
27
|
+
* @returns {Uint8Array}
|
|
28
|
+
*/
|
|
29
|
+
export function asU8A (buf) {
|
|
30
|
+
/* c8 ignore next */
|
|
31
|
+
if (!(buf instanceof Uint8Array)) {
|
|
32
|
+
return Uint8Array.from(buf)
|
|
33
|
+
}
|
|
34
|
+
return isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const toString = useBuffer
|
|
38
|
+
? // eslint-disable-line operator-linebreak
|
|
39
|
+
/**
|
|
40
|
+
* @param {Uint8Array} bytes
|
|
41
|
+
* @param {number} start
|
|
42
|
+
* @param {number} end
|
|
43
|
+
*/
|
|
44
|
+
(bytes, start, end) => {
|
|
45
|
+
return end - start > 64
|
|
46
|
+
? // eslint-disable-line operator-linebreak
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
globalThis.Buffer.from(bytes.subarray(start, end)).toString('utf8')
|
|
49
|
+
: utf8Slice(bytes, start, end)
|
|
50
|
+
}
|
|
51
|
+
/* c8 ignore next 11 */
|
|
52
|
+
: // eslint-disable-line operator-linebreak
|
|
53
|
+
/**
|
|
54
|
+
* @param {Uint8Array} bytes
|
|
55
|
+
* @param {number} start
|
|
56
|
+
* @param {number} end
|
|
57
|
+
*/
|
|
58
|
+
(bytes, start, end) => {
|
|
59
|
+
return end - start > 64
|
|
60
|
+
? textDecoder.decode(bytes.subarray(start, end))
|
|
61
|
+
: utf8Slice(bytes, start, end)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const fromString = useBuffer
|
|
65
|
+
? // eslint-disable-line operator-linebreak
|
|
66
|
+
/**
|
|
67
|
+
* @param {string} string
|
|
68
|
+
*/
|
|
69
|
+
(string) => {
|
|
70
|
+
return string.length > 64
|
|
71
|
+
? // eslint-disable-line operator-linebreak
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
globalThis.Buffer.from(string)
|
|
74
|
+
: utf8ToBytes(string)
|
|
75
|
+
}
|
|
76
|
+
/* c8 ignore next 7 */
|
|
77
|
+
: // eslint-disable-line operator-linebreak
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} string
|
|
80
|
+
*/
|
|
81
|
+
(string) => {
|
|
82
|
+
return string.length > 64 ? textEncoder.encode(string) : utf8ToBytes(string)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Buffer variant not fast enough for what we need
|
|
87
|
+
* @param {number[]} arr
|
|
88
|
+
* @returns {Uint8Array}
|
|
89
|
+
*/
|
|
90
|
+
export const fromArray = (arr) => {
|
|
91
|
+
return Uint8Array.from(arr)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const slice = useBuffer
|
|
95
|
+
? // eslint-disable-line operator-linebreak
|
|
96
|
+
/**
|
|
97
|
+
* @param {Uint8Array} bytes
|
|
98
|
+
* @param {number} start
|
|
99
|
+
* @param {number} end
|
|
100
|
+
*/
|
|
101
|
+
(bytes, start, end) => {
|
|
102
|
+
if (isBuffer(bytes)) {
|
|
103
|
+
return new Uint8Array(bytes.subarray(start, end))
|
|
104
|
+
}
|
|
105
|
+
return bytes.slice(start, end)
|
|
106
|
+
}
|
|
107
|
+
/* c8 ignore next 9 */
|
|
108
|
+
: // eslint-disable-line operator-linebreak
|
|
109
|
+
/**
|
|
110
|
+
* @param {Uint8Array} bytes
|
|
111
|
+
* @param {number} start
|
|
112
|
+
* @param {number} end
|
|
113
|
+
*/
|
|
114
|
+
(bytes, start, end) => {
|
|
115
|
+
return bytes.slice(start, end)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const concat = useBuffer
|
|
119
|
+
? // eslint-disable-line operator-linebreak
|
|
120
|
+
/**
|
|
121
|
+
* @param {Uint8Array[]} chunks
|
|
122
|
+
* @param {number} length
|
|
123
|
+
* @returns {Uint8Array}
|
|
124
|
+
*/
|
|
125
|
+
(chunks, length) => {
|
|
126
|
+
// might get a stray plain Array here
|
|
127
|
+
/* c8 ignore next 1 */
|
|
128
|
+
chunks = chunks.map((c) => c instanceof Uint8Array
|
|
129
|
+
? c
|
|
130
|
+
// this case is occasionally missed during test runs so becomes coverage-flaky
|
|
131
|
+
/* c8 ignore next 4 */
|
|
132
|
+
: // eslint-disable-line operator-linebreak
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
globalThis.Buffer.from(c))
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
return asU8A(globalThis.Buffer.concat(chunks, length))
|
|
137
|
+
}
|
|
138
|
+
/* c8 ignore next 19 */
|
|
139
|
+
: // eslint-disable-line operator-linebreak
|
|
140
|
+
/**
|
|
141
|
+
* @param {Uint8Array[]} chunks
|
|
142
|
+
* @param {number} length
|
|
143
|
+
* @returns {Uint8Array}
|
|
144
|
+
*/
|
|
145
|
+
(chunks, length) => {
|
|
146
|
+
const out = new Uint8Array(length)
|
|
147
|
+
let off = 0
|
|
148
|
+
for (let b of chunks) {
|
|
149
|
+
if (off + b.length > out.length) {
|
|
150
|
+
// final chunk that's bigger than we need
|
|
151
|
+
b = b.subarray(0, out.length - off)
|
|
152
|
+
}
|
|
153
|
+
out.set(b, off)
|
|
154
|
+
off += b.length
|
|
155
|
+
}
|
|
156
|
+
return out
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const alloc = useBuffer
|
|
160
|
+
? // eslint-disable-line operator-linebreak
|
|
161
|
+
/**
|
|
162
|
+
* @param {number} size
|
|
163
|
+
* @returns {Uint8Array}
|
|
164
|
+
*/
|
|
165
|
+
(size) => {
|
|
166
|
+
// we always write over the contents we expose so this should be safe
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
return globalThis.Buffer.allocUnsafe(size)
|
|
169
|
+
}
|
|
170
|
+
/* c8 ignore next 8 */
|
|
171
|
+
: // eslint-disable-line operator-linebreak
|
|
172
|
+
/**
|
|
173
|
+
* @param {number} size
|
|
174
|
+
* @returns {Uint8Array}
|
|
175
|
+
*/
|
|
176
|
+
(size) => {
|
|
177
|
+
return new Uint8Array(size)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const toHex = useBuffer
|
|
181
|
+
? // eslint-disable-line operator-linebreak
|
|
182
|
+
/**
|
|
183
|
+
* @param {Uint8Array} d
|
|
184
|
+
* @returns {string}
|
|
185
|
+
*/
|
|
186
|
+
(d) => {
|
|
187
|
+
if (typeof d === 'string') {
|
|
188
|
+
return d
|
|
189
|
+
}
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
return globalThis.Buffer.from(toBytes(d)).toString('hex')
|
|
192
|
+
}
|
|
193
|
+
/* c8 ignore next 12 */
|
|
194
|
+
: // eslint-disable-line operator-linebreak
|
|
195
|
+
/**
|
|
196
|
+
* @param {Uint8Array} d
|
|
197
|
+
* @returns {string}
|
|
198
|
+
*/
|
|
199
|
+
(d) => {
|
|
200
|
+
if (typeof d === 'string') {
|
|
201
|
+
return d
|
|
202
|
+
}
|
|
203
|
+
// @ts-ignore not smart enough to figure this out
|
|
204
|
+
return Array.prototype.reduce.call(toBytes(d), (p, c) => `${p}${c.toString(16).padStart(2, '0')}`, '')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export const fromHex = useBuffer
|
|
208
|
+
? // eslint-disable-line operator-linebreak
|
|
209
|
+
/**
|
|
210
|
+
* @param {string|Uint8Array} hex
|
|
211
|
+
* @returns {Uint8Array}
|
|
212
|
+
*/
|
|
213
|
+
(hex) => {
|
|
214
|
+
if (hex instanceof Uint8Array) {
|
|
215
|
+
return hex
|
|
216
|
+
}
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
return globalThis.Buffer.from(hex, 'hex')
|
|
219
|
+
}
|
|
220
|
+
/* c8 ignore next 17 */
|
|
221
|
+
: // eslint-disable-line operator-linebreak
|
|
222
|
+
/**
|
|
223
|
+
* @param {string|Uint8Array} hex
|
|
224
|
+
* @returns {Uint8Array}
|
|
225
|
+
*/
|
|
226
|
+
(hex) => {
|
|
227
|
+
if (hex instanceof Uint8Array) {
|
|
228
|
+
return hex
|
|
229
|
+
}
|
|
230
|
+
if (!hex.length) {
|
|
231
|
+
return new Uint8Array(0)
|
|
232
|
+
}
|
|
233
|
+
return new Uint8Array(hex.split('')
|
|
234
|
+
.map((/** @type {string} */ c, /** @type {number} */ i, /** @type {string[]} */ d) => i % 2 === 0 ? `0x${c}${d[i + 1]}` : '')
|
|
235
|
+
.filter(Boolean)
|
|
236
|
+
.map((/** @type {string} */ e) => parseInt(e, 16)))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param {Uint8Array|ArrayBuffer|ArrayBufferView} obj
|
|
241
|
+
* @returns {Uint8Array}
|
|
242
|
+
*/
|
|
243
|
+
function toBytes (obj) {
|
|
244
|
+
if (obj instanceof Uint8Array && obj.constructor.name === 'Uint8Array') {
|
|
245
|
+
return obj
|
|
246
|
+
}
|
|
247
|
+
if (obj instanceof ArrayBuffer) {
|
|
248
|
+
return new Uint8Array(obj)
|
|
249
|
+
}
|
|
250
|
+
if (ArrayBuffer.isView(obj)) {
|
|
251
|
+
return new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength)
|
|
252
|
+
}
|
|
253
|
+
/* c8 ignore next */
|
|
254
|
+
throw new Error('Unknown type, must be binary type')
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @param {Uint8Array} b1
|
|
259
|
+
* @param {Uint8Array} b2
|
|
260
|
+
* @returns {number}
|
|
261
|
+
*/
|
|
262
|
+
export function compare (b1, b2) {
|
|
263
|
+
/* c8 ignore next 5 */
|
|
264
|
+
if (isBuffer(b1) && isBuffer(b2)) {
|
|
265
|
+
// probably not possible to get here in the current API
|
|
266
|
+
// @ts-ignore Buffer
|
|
267
|
+
return b1.compare(b2)
|
|
268
|
+
}
|
|
269
|
+
for (let i = 0; i < b1.length; i++) {
|
|
270
|
+
if (b1[i] === b2[i]) {
|
|
271
|
+
continue
|
|
272
|
+
}
|
|
273
|
+
return b1[i] < b2[i] ? -1 : 1
|
|
274
|
+
} /* c8 ignore next 3 */
|
|
275
|
+
return 0
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// The below code is taken from https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
279
|
+
// Licensed Apache-2.0.
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {string} str
|
|
283
|
+
* @returns {number[]}
|
|
284
|
+
*/
|
|
285
|
+
function utf8ToBytes (str) {
|
|
286
|
+
const out = []
|
|
287
|
+
let p = 0
|
|
288
|
+
for (let i = 0; i < str.length; i++) {
|
|
289
|
+
let c = str.charCodeAt(i)
|
|
290
|
+
if (c < 128) {
|
|
291
|
+
out[p++] = c
|
|
292
|
+
} else if (c < 2048) {
|
|
293
|
+
out[p++] = (c >> 6) | 192
|
|
294
|
+
out[p++] = (c & 63) | 128
|
|
295
|
+
} else if (
|
|
296
|
+
((c & 0xFC00) === 0xD800) && (i + 1) < str.length &&
|
|
297
|
+
((str.charCodeAt(i + 1) & 0xFC00) === 0xDC00)) {
|
|
298
|
+
// Surrogate Pair
|
|
299
|
+
c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF)
|
|
300
|
+
out[p++] = (c >> 18) | 240
|
|
301
|
+
out[p++] = ((c >> 12) & 63) | 128
|
|
302
|
+
out[p++] = ((c >> 6) & 63) | 128
|
|
303
|
+
out[p++] = (c & 63) | 128
|
|
304
|
+
} else {
|
|
305
|
+
out[p++] = (c >> 12) | 224
|
|
306
|
+
out[p++] = ((c >> 6) & 63) | 128
|
|
307
|
+
out[p++] = (c & 63) | 128
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return out
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// The below code is mostly taken from https://github.com/feross/buffer
|
|
314
|
+
// Licensed MIT. Copyright (c) Feross Aboukhadijeh
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @param {Uint8Array} buf
|
|
318
|
+
* @param {number} offset
|
|
319
|
+
* @param {number} end
|
|
320
|
+
* @returns {string}
|
|
321
|
+
*/
|
|
322
|
+
function utf8Slice (buf, offset, end) {
|
|
323
|
+
const res = []
|
|
324
|
+
|
|
325
|
+
while (offset < end) {
|
|
326
|
+
const firstByte = buf[offset]
|
|
327
|
+
let codePoint = null
|
|
328
|
+
let bytesPerSequence = (firstByte > 0xef) ? 4 : (firstByte > 0xdf) ? 3 : (firstByte > 0xbf) ? 2 : 1
|
|
329
|
+
|
|
330
|
+
if (offset + bytesPerSequence <= end) {
|
|
331
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint
|
|
332
|
+
|
|
333
|
+
switch (bytesPerSequence) {
|
|
334
|
+
case 1:
|
|
335
|
+
if (firstByte < 0x80) {
|
|
336
|
+
codePoint = firstByte
|
|
337
|
+
}
|
|
338
|
+
break
|
|
339
|
+
case 2:
|
|
340
|
+
secondByte = buf[offset + 1]
|
|
341
|
+
if ((secondByte & 0xc0) === 0x80) {
|
|
342
|
+
tempCodePoint = (firstByte & 0x1f) << 0x6 | (secondByte & 0x3f)
|
|
343
|
+
if (tempCodePoint > 0x7f) {
|
|
344
|
+
codePoint = tempCodePoint
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
break
|
|
348
|
+
case 3:
|
|
349
|
+
secondByte = buf[offset + 1]
|
|
350
|
+
thirdByte = buf[offset + 2]
|
|
351
|
+
if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) {
|
|
352
|
+
tempCodePoint = (firstByte & 0xf) << 0xc | (secondByte & 0x3f) << 0x6 | (thirdByte & 0x3f)
|
|
353
|
+
/* c8 ignore next 3 */
|
|
354
|
+
if (tempCodePoint > 0x7ff && (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff)) {
|
|
355
|
+
codePoint = tempCodePoint
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
break
|
|
359
|
+
case 4:
|
|
360
|
+
secondByte = buf[offset + 1]
|
|
361
|
+
thirdByte = buf[offset + 2]
|
|
362
|
+
fourthByte = buf[offset + 3]
|
|
363
|
+
if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80 && (fourthByte & 0xc0) === 0x80) {
|
|
364
|
+
tempCodePoint = (firstByte & 0xf) << 0x12 | (secondByte & 0x3f) << 0xc | (thirdByte & 0x3f) << 0x6 | (fourthByte & 0x3f)
|
|
365
|
+
if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) {
|
|
366
|
+
codePoint = tempCodePoint
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/* c8 ignore next 5 */
|
|
373
|
+
if (codePoint === null) {
|
|
374
|
+
// we did not generate a valid codePoint so insert a
|
|
375
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
376
|
+
codePoint = 0xfffd
|
|
377
|
+
bytesPerSequence = 1
|
|
378
|
+
} else if (codePoint > 0xffff) {
|
|
379
|
+
// encode to utf16 (surrogate pair dance)
|
|
380
|
+
codePoint -= 0x10000
|
|
381
|
+
res.push(codePoint >>> 10 & 0x3ff | 0xd800)
|
|
382
|
+
codePoint = 0xdc00 | codePoint & 0x3ff
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
res.push(codePoint)
|
|
386
|
+
offset += bytesPerSequence
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return decodeCodePointsArray(res)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
393
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
394
|
+
// We go 1 magnitude less, for safety
|
|
395
|
+
const MAX_ARGUMENTS_LENGTH = 0x1000
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @param {number[]} codePoints
|
|
399
|
+
* @returns {string}
|
|
400
|
+
*/
|
|
401
|
+
export function decodeCodePointsArray (codePoints) {
|
|
402
|
+
const len = codePoints.length
|
|
403
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
404
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
405
|
+
}
|
|
406
|
+
/* c8 ignore next 10 */
|
|
407
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
408
|
+
let res = ''
|
|
409
|
+
let i = 0
|
|
410
|
+
while (i < len) {
|
|
411
|
+
res += String.fromCharCode.apply(
|
|
412
|
+
String,
|
|
413
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
return res
|
|
417
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const decodeErrPrefix = 'CBOR decode error:'
|
|
2
|
+
const encodeErrPrefix = 'CBOR encode error:'
|
|
3
|
+
|
|
4
|
+
const uintMinorPrefixBytes = []
|
|
5
|
+
uintMinorPrefixBytes[23] = 1
|
|
6
|
+
uintMinorPrefixBytes[24] = 2
|
|
7
|
+
uintMinorPrefixBytes[25] = 3
|
|
8
|
+
uintMinorPrefixBytes[26] = 5
|
|
9
|
+
uintMinorPrefixBytes[27] = 9
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Uint8Array} data
|
|
13
|
+
* @param {number} pos
|
|
14
|
+
* @param {number} need
|
|
15
|
+
*/
|
|
16
|
+
function assertEnoughData (data, pos, need) {
|
|
17
|
+
if (data.length - pos < need) {
|
|
18
|
+
throw new Error(`${decodeErrPrefix} not enough data for type`)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
decodeErrPrefix,
|
|
24
|
+
encodeErrPrefix,
|
|
25
|
+
uintMinorPrefixBytes,
|
|
26
|
+
assertEnoughData
|
|
27
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { decodeErrPrefix } from './common.js'
|
|
2
|
+
import { Type } from './token.js'
|
|
3
|
+
import { jump, quick } from './jump.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('./token.js').Token} Token
|
|
7
|
+
* @typedef {import('../interface').DecodeOptions} DecodeOptions
|
|
8
|
+
* @typedef {import('../interface').DecodeTokenizer} DecodeTokenizer
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const defaultDecodeOptions = {
|
|
12
|
+
strict: false,
|
|
13
|
+
allowIndefinite: true,
|
|
14
|
+
allowUndefined: true,
|
|
15
|
+
allowBigInt: true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @implements {DecodeTokenizer}
|
|
20
|
+
*/
|
|
21
|
+
class Tokeniser {
|
|
22
|
+
/**
|
|
23
|
+
* @param {Uint8Array} data
|
|
24
|
+
* @param {DecodeOptions} options
|
|
25
|
+
*/
|
|
26
|
+
constructor (data, options = {}) {
|
|
27
|
+
this._pos = 0
|
|
28
|
+
this.data = data
|
|
29
|
+
this.options = options
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pos () {
|
|
33
|
+
return this._pos
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
done () {
|
|
37
|
+
return this._pos >= this.data.length
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
next () {
|
|
41
|
+
const byt = this.data[this._pos]
|
|
42
|
+
let token = quick[byt]
|
|
43
|
+
if (token === undefined) {
|
|
44
|
+
const decoder = jump[byt]
|
|
45
|
+
/* c8 ignore next 4 */
|
|
46
|
+
// if we're here then there's something wrong with our jump or quick lists!
|
|
47
|
+
if (!decoder) {
|
|
48
|
+
throw new Error(`${decodeErrPrefix} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, '0')})`)
|
|
49
|
+
}
|
|
50
|
+
const minor = byt & 31
|
|
51
|
+
token = decoder(this.data, this._pos, minor, this.options)
|
|
52
|
+
}
|
|
53
|
+
// @ts-ignore we get to assume encodedLength is set (crossing fingers slightly)
|
|
54
|
+
this._pos += token.encodedLength
|
|
55
|
+
return token
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const DONE = Symbol.for('DONE')
|
|
60
|
+
const BREAK = Symbol.for('BREAK')
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {Token} token
|
|
64
|
+
* @param {DecodeTokenizer} tokeniser
|
|
65
|
+
* @param {DecodeOptions} options
|
|
66
|
+
* @returns {any|BREAK|DONE}
|
|
67
|
+
*/
|
|
68
|
+
function tokenToArray (token, tokeniser, options) {
|
|
69
|
+
const arr = []
|
|
70
|
+
for (let i = 0; i < token.value; i++) {
|
|
71
|
+
const value = tokensToObject(tokeniser, options)
|
|
72
|
+
if (value === BREAK) {
|
|
73
|
+
if (token.value === Infinity) {
|
|
74
|
+
// normal end to indefinite length array
|
|
75
|
+
break
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed array`)
|
|
78
|
+
}
|
|
79
|
+
if (value === DONE) {
|
|
80
|
+
throw new Error(`${decodeErrPrefix} found array but not enough entries (got ${i}, expected ${token.value})`)
|
|
81
|
+
}
|
|
82
|
+
arr[i] = value
|
|
83
|
+
}
|
|
84
|
+
return arr
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {Token} token
|
|
89
|
+
* @param {DecodeTokenizer} tokeniser
|
|
90
|
+
* @param {DecodeOptions} options
|
|
91
|
+
* @returns {any|BREAK|DONE}
|
|
92
|
+
*/
|
|
93
|
+
function tokenToMap (token, tokeniser, options) {
|
|
94
|
+
const useMaps = options.useMaps === true
|
|
95
|
+
const obj = useMaps ? undefined : {}
|
|
96
|
+
const m = useMaps ? new Map() : undefined
|
|
97
|
+
for (let i = 0; i < token.value; i++) {
|
|
98
|
+
const key = tokensToObject(tokeniser, options)
|
|
99
|
+
if (key === BREAK) {
|
|
100
|
+
if (token.value === Infinity) {
|
|
101
|
+
// normal end to indefinite length map
|
|
102
|
+
break
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`)
|
|
105
|
+
}
|
|
106
|
+
if (key === DONE) {
|
|
107
|
+
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`)
|
|
108
|
+
}
|
|
109
|
+
if (useMaps !== true && typeof key !== 'string') {
|
|
110
|
+
throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`)
|
|
111
|
+
}
|
|
112
|
+
if (options.rejectDuplicateMapKeys === true) {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
if ((useMaps && m.has(key)) || (!useMaps && (key in obj))) {
|
|
115
|
+
throw new Error(`${decodeErrPrefix} found repeat map key "${key}"`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const value = tokensToObject(tokeniser, options)
|
|
119
|
+
if (value === DONE) {
|
|
120
|
+
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`)
|
|
121
|
+
}
|
|
122
|
+
if (useMaps) {
|
|
123
|
+
// @ts-ignore TODO reconsider this .. maybe needs to be strict about key types
|
|
124
|
+
m.set(key, value)
|
|
125
|
+
} else {
|
|
126
|
+
// @ts-ignore TODO reconsider this .. maybe needs to be strict about key types
|
|
127
|
+
obj[key] = value
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// @ts-ignore c'mon man
|
|
131
|
+
return useMaps ? m : obj
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {DecodeTokenizer} tokeniser
|
|
136
|
+
* @param {DecodeOptions} options
|
|
137
|
+
* @returns {any|BREAK|DONE}
|
|
138
|
+
*/
|
|
139
|
+
function tokensToObject (tokeniser, options) {
|
|
140
|
+
// should we support array as an argument?
|
|
141
|
+
// check for tokenIter[Symbol.iterator] and replace tokenIter with what that returns?
|
|
142
|
+
if (tokeniser.done()) {
|
|
143
|
+
return DONE
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const token = tokeniser.next()
|
|
147
|
+
|
|
148
|
+
if (token.type.equals(Type.break)) {
|
|
149
|
+
return BREAK
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (token.type.terminal) {
|
|
153
|
+
return token.value
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (token.type.equals(Type.array)) {
|
|
157
|
+
return tokenToArray(token, tokeniser, options)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (token.type.equals(Type.map)) {
|
|
161
|
+
return tokenToMap(token, tokeniser, options)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (token.type.equals(Type.tag)) {
|
|
165
|
+
if (options.tags && typeof options.tags[token.value] === 'function') {
|
|
166
|
+
const tagged = tokensToObject(tokeniser, options)
|
|
167
|
+
return options.tags[token.value](tagged)
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`${decodeErrPrefix} tag not supported (${token.value})`)
|
|
170
|
+
}
|
|
171
|
+
/* c8 ignore next */
|
|
172
|
+
throw new Error('unsupported')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @param {Uint8Array} data
|
|
177
|
+
* @param {DecodeOptions} [options]
|
|
178
|
+
* @returns {[any, Uint8Array]}
|
|
179
|
+
*/
|
|
180
|
+
function decodeFirst (data, options) {
|
|
181
|
+
if (!(data instanceof Uint8Array)) {
|
|
182
|
+
throw new Error(`${decodeErrPrefix} data to decode must be a Uint8Array`)
|
|
183
|
+
}
|
|
184
|
+
options = Object.assign({}, defaultDecodeOptions, options)
|
|
185
|
+
const tokeniser = options.tokenizer || new Tokeniser(data, options)
|
|
186
|
+
const decoded = tokensToObject(tokeniser, options)
|
|
187
|
+
if (decoded === DONE) {
|
|
188
|
+
throw new Error(`${decodeErrPrefix} did not find any content to decode`)
|
|
189
|
+
}
|
|
190
|
+
if (decoded === BREAK) {
|
|
191
|
+
throw new Error(`${decodeErrPrefix} got unexpected break`)
|
|
192
|
+
}
|
|
193
|
+
return [decoded, data.subarray(tokeniser.pos())]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {Uint8Array} data
|
|
198
|
+
* @param {DecodeOptions} [options]
|
|
199
|
+
* @returns {any}
|
|
200
|
+
*/
|
|
201
|
+
function decode (data, options) {
|
|
202
|
+
const [decoded, remainder] = decodeFirst(data, options)
|
|
203
|
+
if (remainder.length > 0) {
|
|
204
|
+
throw new Error(`${decodeErrPrefix} too many terminals, data makes no sense`)
|
|
205
|
+
}
|
|
206
|
+
return decoded
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { Tokeniser, tokensToObject, decode, decodeFirst }
|