@ipld/car 5.0.3 → 5.1.1
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/README.md +124 -14
- package/dist/index.min.js +3 -3
- package/dist/src/api.d.ts +16 -0
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/buffer-decoder.d.ts +67 -0
- package/dist/src/buffer-decoder.d.ts.map +1 -0
- package/dist/src/buffer-reader-browser.d.ts +116 -0
- package/dist/src/buffer-reader-browser.d.ts.map +1 -0
- package/dist/src/buffer-reader.d.ts +31 -0
- package/dist/src/buffer-reader.d.ts.map +1 -0
- package/dist/src/coding.d.ts +10 -3
- package/dist/src/coding.d.ts.map +1 -1
- package/dist/src/decoder-common.d.ts +43 -0
- package/dist/src/decoder-common.d.ts.map +1 -0
- package/dist/src/decoder.d.ts +10 -0
- package/dist/src/decoder.d.ts.map +1 -1
- package/dist/src/index-browser.d.ts +3 -1
- package/dist/src/index.d.ts +2 -1
- package/package.json +8 -2
- package/src/api.ts +18 -0
- package/src/buffer-decoder.js +226 -0
- package/src/buffer-reader-browser.js +150 -0
- package/src/buffer-reader.js +53 -0
- package/src/coding.ts +13 -3
- package/src/decoder-common.js +86 -0
- package/src/decoder.js +31 -93
- package/src/index-browser.js +5 -1
- package/src/index.js +2 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @ipld/car
|
|
2
2
|
|
|
3
3
|
[](https://codecov.io/gh/ipld/js-car)
|
|
4
|
-
[](https://github.com/ipld/js-car/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
|
|
5
5
|
|
|
6
6
|
> Content Addressable aRchive format reader and writer
|
|
7
7
|
|
|
@@ -13,16 +13,16 @@ $ npm i @ipld/car
|
|
|
13
13
|
|
|
14
14
|
See also:
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
- Original [Go implementation](https://github.com/ipfs/go-car)
|
|
17
|
+
- [CAR specification](https://github.com/ipld/specs/blob/master/block-layer/content-addressable-archives.md)
|
|
18
|
+
- [IPLD](https://ipld.io)
|
|
19
19
|
|
|
20
20
|
## Contents
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
- [Example](#example)
|
|
23
|
+
- [Usage](#usage)
|
|
24
|
+
- [API](#api)
|
|
25
|
+
- [License](#license)
|
|
26
26
|
|
|
27
27
|
## Example
|
|
28
28
|
|
|
@@ -37,7 +37,7 @@ import * as raw from 'multiformats/codecs/raw'
|
|
|
37
37
|
import { CID } from 'multiformats/cid'
|
|
38
38
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
39
39
|
|
|
40
|
-
async function example
|
|
40
|
+
async function example() {
|
|
41
41
|
const bytes = new TextEncoder().encode('random meaningless bytes')
|
|
42
42
|
const hash = await sha256.digest(raw.encode(bytes))
|
|
43
43
|
const cid = CID.create(1, raw.code, hash)
|
|
@@ -61,9 +61,11 @@ async function example () {
|
|
|
61
61
|
const got = await reader.get(roots[0])
|
|
62
62
|
// also possible: for await (const { cid, bytes } of CarIterator.fromIterable(inStream)) { ... }
|
|
63
63
|
|
|
64
|
-
console.log(
|
|
64
|
+
console.log(
|
|
65
|
+
'Retrieved [%s] from example.car with CID [%s]',
|
|
65
66
|
new TextDecoder().decode(got.bytes),
|
|
66
|
-
roots[0].toString()
|
|
67
|
+
roots[0].toString()
|
|
68
|
+
)
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
example().catch((err) => {
|
|
@@ -99,6 +101,7 @@ The basic `CarReader` class is consumed via:
|
|
|
99
101
|
|
|
100
102
|
```js
|
|
101
103
|
import { CarReader } from '@ipld/car/reader'
|
|
104
|
+
import { CarBufferReader } from '@ipld/car/buffer-reader'
|
|
102
105
|
```
|
|
103
106
|
|
|
104
107
|
Or alternatively: `import { CarReader } from '@ipld/car'`. CommonJS `require`
|
|
@@ -107,7 +110,7 @@ will also work for the same import paths and references.
|
|
|
107
110
|
`CarReader` is useful for relatively small CAR archives as it buffers the
|
|
108
111
|
entirety of the archive in memory to provide access to its data. This class is
|
|
109
112
|
also suitable in a browser environment. The `CarReader` class provides
|
|
110
|
-
random-access [`get(key)`](#CarReader_get) and
|
|
113
|
+
random-access [`get(key)`](#CarReader_get) and [`has(key)`](#CarReader_has)
|
|
111
114
|
methods as well as iterators for [`blocks()`](#CarReader_blocks)] and
|
|
112
115
|
[`cids()`](#CarReader_cids)].
|
|
113
116
|
|
|
@@ -116,6 +119,8 @@ methods as well as iterators for [`blocks()`](#CarReader_blocks)] and
|
|
|
116
119
|
[an `AsyncIterable`](#CarReader__fromIterable) of `Uint8Array`s (note that
|
|
117
120
|
Node.js streams are `AsyncIterable`s and can be consumed in this way).
|
|
118
121
|
|
|
122
|
+
`CarBufferReader` works exactly the same way as `CarReader` but all methods are synchronous.
|
|
123
|
+
|
|
119
124
|
### [`CarIndexedReader`](#CarIndexedReader)
|
|
120
125
|
|
|
121
126
|
The `CarIndexedReader` class is a special form of `CarReader` and can be
|
|
@@ -263,6 +268,14 @@ be directly fed to a
|
|
|
263
268
|
* [`decoder.bytesReader(bytes)`](#decoder__bytesReader__bytes__)
|
|
264
269
|
* [`decoder.asyncIterableReader(asyncIterable)`](#decoder__asyncIterableReader__asyncIterable__)
|
|
265
270
|
* [`decoder.limitReader(reader, byteLimit)`](#decoder__limitReader__reader____byteLimit__)
|
|
271
|
+
* [`class CarBufferReader`](#CarBufferReader)
|
|
272
|
+
* [`CarBufferReader#getRoots()`](#CarBufferReader_getRoots)
|
|
273
|
+
* [`CarBufferReader#has(key)`](#CarBufferReader_has)
|
|
274
|
+
* [`CarBufferReader#get(key)`](#CarBufferReader_get)
|
|
275
|
+
* [`CarBufferReader#blocks()`](#CarBufferReader_blocks)
|
|
276
|
+
* [`CarBufferReader#cids()`](#CarBufferReader_cids)
|
|
277
|
+
* [`CarBufferReader.fromBytes(bytes)`](#CarBufferReader__fromBytes)
|
|
278
|
+
* [`CarBufferReader.readRaw(fd, blockIndex)`](#CarBufferReader__readRaw)
|
|
266
279
|
|
|
267
280
|
<a name="CarReader"></a>
|
|
268
281
|
### `class CarReader`
|
|
@@ -948,12 +961,109 @@ Wraps a `BytesReader` in a limiting `BytesReader` which limits maximum read
|
|
|
948
961
|
to `byteLimit` bytes. It _does not_ update `pos` of the original
|
|
949
962
|
`BytesReader`.
|
|
950
963
|
|
|
964
|
+
<a name="CarBufferReader"></a>
|
|
965
|
+
### `class CarBufferReader`
|
|
966
|
+
|
|
967
|
+
Properties:
|
|
968
|
+
|
|
969
|
+
* `version` `(number)`: The version number of the CAR referenced by this
|
|
970
|
+
reader (should be `1` or `2`).
|
|
971
|
+
|
|
972
|
+
Provides blockstore-like access to a CAR.
|
|
973
|
+
|
|
974
|
+
Implements the `RootsBufferReader` interface:
|
|
975
|
+
[`getRoots()`](#ICarBufferReader__getRoots). And the `BlockBufferReader` interface:
|
|
976
|
+
[`get()`](#ICarBufferReader__get), [`has()`](#ICarBufferReader__has),
|
|
977
|
+
[`blocks()`](#ICarBufferReader__blocks) and
|
|
978
|
+
[`cids()`](#ICarBufferReader__cids).
|
|
979
|
+
|
|
980
|
+
Load this class with either `import { CarBufferReader } from '@ipld/car/buffer-reader'`
|
|
981
|
+
(`const { CarBufferReader } = require('@ipld/car/buffer-reader')`). Or
|
|
982
|
+
`import { CarBufferReader } from '@ipld/car'` (`const { CarBufferReader } = require('@ipld/car')`).
|
|
983
|
+
The former will likely result in smaller bundle sizes where this is
|
|
984
|
+
important.
|
|
985
|
+
|
|
986
|
+
<a name="CarBufferReader_getRoots"></a>
|
|
987
|
+
### `CarBufferReader#getRoots()`
|
|
988
|
+
|
|
989
|
+
* Returns: `CID[]`
|
|
990
|
+
|
|
991
|
+
Get the list of roots defined by the CAR referenced by this reader. May be
|
|
992
|
+
zero or more `CID`s.
|
|
993
|
+
|
|
994
|
+
<a name="CarBufferReader_has"></a>
|
|
995
|
+
### `CarBufferReader#has(key)`
|
|
996
|
+
|
|
997
|
+
* `key` `(CID)`
|
|
998
|
+
|
|
999
|
+
* Returns: `boolean`
|
|
1000
|
+
|
|
1001
|
+
Check whether a given `CID` exists within the CAR referenced by this
|
|
1002
|
+
reader.
|
|
1003
|
+
|
|
1004
|
+
<a name="CarBufferReader_get"></a>
|
|
1005
|
+
### `CarBufferReader#get(key)`
|
|
1006
|
+
|
|
1007
|
+
* `key` `(CID)`
|
|
1008
|
+
|
|
1009
|
+
* Returns: `Block|undefined`
|
|
1010
|
+
|
|
1011
|
+
Fetch a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) from the CAR
|
|
1012
|
+
referenced by this reader matching the provided `CID`. In the case where
|
|
1013
|
+
the provided `CID` doesn't exist within the CAR, `undefined` will be
|
|
1014
|
+
returned.
|
|
1015
|
+
|
|
1016
|
+
<a name="CarBufferReader_blocks"></a>
|
|
1017
|
+
### `CarBufferReader#blocks()`
|
|
1018
|
+
|
|
1019
|
+
* Returns: `Block[]`
|
|
1020
|
+
|
|
1021
|
+
Returns a `Block[]` of the `Block`s (`{ cid:CID, bytes:Uint8Array }` pairs) contained within
|
|
1022
|
+
the CAR referenced by this reader.
|
|
1023
|
+
|
|
1024
|
+
<a name="CarBufferReader_cids"></a>
|
|
1025
|
+
### `CarBufferReader#cids()`
|
|
1026
|
+
|
|
1027
|
+
* Returns: `CID[]`
|
|
1028
|
+
|
|
1029
|
+
Returns a `CID[]` of the `CID`s contained within the CAR referenced by this reader.
|
|
1030
|
+
|
|
1031
|
+
<a name="CarBufferReader__fromBytes"></a>
|
|
1032
|
+
### `CarBufferReader.fromBytes(bytes)`
|
|
1033
|
+
|
|
1034
|
+
* `bytes` `(Uint8Array)`
|
|
1035
|
+
|
|
1036
|
+
* Returns: `CarBufferReader`
|
|
1037
|
+
|
|
1038
|
+
Instantiate a [`CarBufferReader`](#CarBufferReader) from a `Uint8Array` blob. This performs a
|
|
1039
|
+
decode fully in memory and maintains the decoded state in memory for full
|
|
1040
|
+
access to the data via the `CarReader` API.
|
|
1041
|
+
|
|
1042
|
+
<a name="CarBufferReader__readRaw"></a>
|
|
1043
|
+
### `CarBufferReader.readRaw(fd, blockIndex)`
|
|
1044
|
+
|
|
1045
|
+
* `fd` `(number)`: A file descriptor from the
|
|
1046
|
+
Node.js `fs` module. An integer, from `fs.open()`.
|
|
1047
|
+
* `blockIndex` `(BlockIndex)`: An index pointing to the location of the
|
|
1048
|
+
Block required. This `BlockIndex` should take the form:
|
|
1049
|
+
`{cid:CID, blockLength:number, blockOffset:number}`.
|
|
1050
|
+
|
|
1051
|
+
* Returns: `Block`: A `{ cid:CID, bytes:Uint8Array }` pair.
|
|
1052
|
+
|
|
1053
|
+
Reads a block directly from a file descriptor for an open CAR file. This
|
|
1054
|
+
function is **only available in Node.js** and not a browser environment.
|
|
1055
|
+
|
|
1056
|
+
This function can be used in connection with [`CarIndexer`](#CarIndexer) which emits
|
|
1057
|
+
the `BlockIndex` objects that are required by this function.
|
|
1058
|
+
|
|
1059
|
+
The user is responsible for opening and closing the file used in this call.
|
|
1060
|
+
|
|
951
1061
|
## License
|
|
952
1062
|
|
|
953
1063
|
Licensed under either of
|
|
954
1064
|
|
|
955
|
-
|
|
956
|
-
|
|
1065
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
1066
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
957
1067
|
|
|
958
1068
|
### Contribution
|
|
959
1069
|
|
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldCar = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var IpldCar=(()=>{var En=Object.create;var Ie=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var _n=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ut=(e,t)=>{for(var r in t)Ie(e,r,{get:t[r],enumerable:!0})},Tt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of An(t))!Un.call(e,o)&&o!==r&&Ie(e,o,{get:()=>t[o],enumerable:!(n=kn(t,o))||n.enumerable});return e};var Ne=(e,t,r)=>(r=e!=null?En(_n(e)):{},Tt(t||!e||!e.__esModule?Ie(r,"default",{value:e,enumerable:!0}):r,e)),Tn=e=>Tt(Ie({},"__esModule",{value:!0}),e);var It=pe((pi,Bt)=>{Bt.exports=Xe;var St=128,Sn=127,Bn=~Sn,In=Math.pow(2,31);function Xe(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw Xe.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=In;)t[r++]=e&255|St,e/=128;for(;e&Bn;)t[r++]=e&255|St,e>>>=7;return t[r]=e|0,Xe.bytes=r-n+1,t}});var Mt=pe((yi,Ct)=>{Ct.exports=We;var Nn=128,Nt=127;function We(e,n){var r=0,n=n||0,o=0,i=n,a,d=e.length;do{if(i>=d||o>49)throw We.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Nt)<<o:(a&Nt)*Math.pow(2,o),o+=7}while(a>=Nn);return We.bytes=i-n,r}});var zt=pe((mi,$t)=>{var Cn=Math.pow(2,7),Mn=Math.pow(2,14),$n=Math.pow(2,21),zn=Math.pow(2,28),Rn=Math.pow(2,35),On=Math.pow(2,42),Ln=Math.pow(2,49),Dn=Math.pow(2,56),Fn=Math.pow(2,63);$t.exports=function(e){return e<Cn?1:e<Mn?2:e<$n?3:e<zn?4:e<Rn?5:e<On?6:e<Ln?7:e<Dn?8:e<Fn?9:10}});var Ce=pe((wi,Rt)=>{Rt.exports={encode:It(),decode:Mt(),encodingLength:zt()}});var yn=pe(()=>{});var li={};Ut(li,{CarBlockIterator:()=>W,CarBufferWriter:()=>_t,CarCIDIterator:()=>Q,CarIndexedReader:()=>he,CarIndexer:()=>X,CarReader:()=>K,CarWriter:()=>Y});var q=Ne(Ce(),1);var Vn=Dt,Ot=128,Hn=127,Pn=~Hn,qn=Math.pow(2,31);function Dt(e,t,r){t=t||[],r=r||0;for(var n=r;e>=qn;)t[r++]=e&255|Ot,e/=128;for(;e&Pn;)t[r++]=e&255|Ot,e>>>=7;return t[r]=e|0,Dt.bytes=r-n+1,t}var Gn=Qe,jn=128,Lt=127;function Qe(e,n){var r=0,n=n||0,o=0,i=n,a,d=e.length;do{if(i>=d)throw Qe.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&Lt)<<o:(a&Lt)*Math.pow(2,o),o+=7}while(a>=jn);return Qe.bytes=i-n,r}var Jn=Math.pow(2,7),Kn=Math.pow(2,14),Xn=Math.pow(2,21),Wn=Math.pow(2,28),Qn=Math.pow(2,35),Yn=Math.pow(2,42),Zn=Math.pow(2,49),eo=Math.pow(2,56),to=Math.pow(2,63),ro=function(e){return e<Jn?1:e<Kn?2:e<Xn?3:e<Wn?4:e<Qn?5:e<Yn?6:e<Zn?7:e<eo?8:e<to?9:10},no={encode:Vn,decode:Gn,encodingLength:ro},oo=no,ye=oo;var me=(e,t=0)=>[ye.decode(e,t),ye.decode.bytes],ee=(e,t,r=0)=>(ye.encode(e,t,r),t),te=e=>ye.encodingLength(e);var xi=new Uint8Array(0);var Vt=(e,t)=>{if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},re=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var Ht=(e,t)=>{let r=t.byteLength,n=te(e),o=n+te(r),i=new Uint8Array(o+r);return ee(e,i,0),ee(r,i,n),i.set(t,o),new ne(e,r,t,i)},we=e=>{let t=re(e),[r,n]=me(t),[o,i]=me(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new ne(r,o,a,t)},Pt=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Vt(e.bytes,r.bytes)}},ne=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function io(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),a=i.charCodeAt(0);if(r[a]!==255)throw new TypeError(i+" is ambiguous");r[a]=o}var d=e.length,f=e.charAt(0),h=Math.log(d)/Math.log(256),p=Math.log(256)/Math.log(d);function Z(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var x=0,j=0,S=0,C=w.length;S!==C&&w[S]===0;)S++,x++;for(var M=(C-S)*p+1>>>0,_=new Uint8Array(M);S!==C;){for(var $=w[S],F=0,B=M-1;($!==0||F<j)&&B!==-1;B--,F++)$+=256*_[B]>>>0,_[B]=$%d>>>0,$=$/d>>>0;if($!==0)throw new Error("Non-zero carry");j=F,S++}for(var O=M-j;O!==M&&_[O]===0;)O++;for(var Be=f.repeat(x);O<M;++O)Be+=e.charAt(_[O]);return Be}function Se(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var x=0;if(w[x]!==" "){for(var j=0,S=0;w[x]===f;)j++,x++;for(var C=(w.length-x)*h+1>>>0,M=new Uint8Array(C);w[x];){var _=r[w.charCodeAt(x)];if(_===255)return;for(var $=0,F=C-1;(_!==0||$<S)&&F!==-1;F--,$++)_+=d*M[F]>>>0,M[F]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=$,x++}if(w[x]!==" "){for(var B=C-S;B!==C&&M[B]===0;)B++;for(var O=new Uint8Array(j+(C-B)),Be=j;B!==C;)O[Be++]=M[B++];return O}}}function vn(w){var x=Se(w);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:Z,decodeUnsafe:Se,decode:vn}}var so=io,ao=so,Gt=ao;var Ye=class{constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ze=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return jt(this,t)}},et=class{constructor(t){this.decoders=t}or(t){return jt(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},jt=(e,t)=>new et({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),tt=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ye(t,r,n),this.decoder=new Ze(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Jt=({name:e,prefix:t,encode:r,decode:n})=>new tt(e,t,r,n),rt=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Gt(r,t);return Jt({prefix:e,name:t,encode:n,decode:i=>re(o(i))})},co=(e,t,r,n)=>{let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),d=0,f=0,h=0;for(let p=0;p<i;++p){let Z=o[e[p]];if(Z===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|Z,d+=r,d>=8&&(d-=8,a[h++]=255&f>>d)}if(d>=r||255&f<<8-d)throw new SyntaxError("Unexpected end of data");return a},uo=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,d=0;for(let f=0;f<e.length;++f)for(d=d<<8|e[f],a+=8;a>r;)a-=r,i+=t[o&d>>a];if(a&&(i+=t[o&d<<r-a]),n)for(;i.length*r&7;)i+="=";return i},z=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>Jt({prefix:t,name:e,encode(o){return uo(o,n,r)},decode(o){return co(o,n,r,e)}});var L=rt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Si=rt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ge=z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ni=z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ci=z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mi=z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$i=z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),zi=z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ri=z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Oi=z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Li=z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return lo(r,nt(e),t||L.encoder);default:return ho(r,nt(e),t||ge.encoder)}};var Xt=new WeakMap,nt=e=>{let t=Xt.get(e);if(t==null){let r=new Map;return Xt.set(e,r),r}return t},m=class{constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==be)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==po)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return m.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ht(t,r);return m.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return m.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Pt(t.multihash,n.multihash)}toString(t){return Kt(this,t)}toJSON(){return{"/":Kt(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof m)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new m(n,o,i,a||Wt(n,o,i.bytes))}else if(r[yo]===!0){let{version:n,multihash:o,code:i}=r,a=we(o);return m.create(n,i,a)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==be)throw new Error(`Version 0 CID must use dag-pb (code: ${be}) block encoding`);return new m(t,r,n,n.bytes)}case 1:{let o=Wt(t,r,n.bytes);return new m(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return m.create(0,be,t)}static createV1(t,r){return m.create(1,t,r)}static decode(t){let[r,n]=m.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=m.inspectBytes(t),n=r.size-r.multihashSize,o=re(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),a=new ne(r.multihashCode,r.digestSize,i,o);return[r.version===0?m.createV0(a):m.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[Z,Se]=me(t.subarray(r));return r+=Se,Z},o=n(),i=be;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,d=n(),f=n(),h=r+f,p=h-a;return{version:o,codec:i,multihashCode:d,digestSize:f,multihashSize:p,size:h}}static parse(t,r){let[n,o]=fo(t,r),i=m.decode(o);return nt(i).set(n,t),i}},fo=(e,t)=>{switch(e[0]){case"Q":{let r=t||L;return[L.prefix,r.decode(`${L.prefix}${e}`)]}case L.prefix:{let r=t||L;return[L.prefix,r.decode(e)]}case ge.prefix:{let r=t||ge;return[ge.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},lo=(e,t,r)=>{let{prefix:n}=r;if(n!==L.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o},ho=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},be=112,po=18,Wt=(e,t,r)=>{let n=te(e),o=n+te(t),i=new Uint8Array(o+r.byteLength);return ee(e,i,0),ee(t,i,n),i.set(r,o),i},yo=Symbol.for("@ipld/js-cid/CID");var mo=["string","number","bigint","symbol"],wo=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Qt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(mo.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(go(e))return"Buffer";let r=bo(e);return r||"Object"}function go(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function bo(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(wo.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var c=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var oe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",xo=new TextDecoder,vo=new TextEncoder;function Me(e){return oe&&globalThis.Buffer.isBuffer(e)}function ot(e){return e instanceof Uint8Array?Me(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var tr=oe?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Zt(e,t,r):(e,t,r)=>r-t>64?xo.decode(e.subarray(t,r)):Zt(e,t,r),rr=oe?e=>e.length>64?globalThis.Buffer.from(e):Yt(e):e=>e.length>64?vo.encode(e):Yt(e),R=e=>Uint8Array.from(e),ie=oe?(e,t,r)=>Me(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),nr=oe?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ot(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},or=oe?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function ir(e,t){if(Me(e)&&Me(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Yt(e,t=1/0){let r,n=e.length,o=null,i=[];for(let a=0;a<n;++a){if(r=e.charCodeAt(a),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(a+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Zt(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=r){let d,f,h,p;switch(a){case 1:o<128&&(i=o);break;case 2:d=e[t+1],(d&192)===128&&(p=(o&31)<<6|d&63,p>127&&(i=p));break;case 3:d=e[t+1],f=e[t+2],(d&192)===128&&(f&192)===128&&(p=(o&15)<<12|(d&63)<<6|f&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:d=e[t+1],f=e[t+2],h=e[t+3],(d&192)===128&&(f&192)===128&&(h&192)===128&&(p=(o&15)<<18|(d&63)<<12|(f&63)<<6|h&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return Eo(n)}var er=4096;function Eo(e){let t=e.length;if(t<=er)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=er));return r}var ko=256,xe=class{constructor(t=ko){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=or(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=ie(n,0,this.cursor)}else r=nr(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",it="CBOR encode error:",ve=[];ve[23]=1;ve[24]=2;ve[25]=3;ve[26]=5;ve[27]=9;function D(e,t,r){if(e.length-t<r)throw new Error(`${l} not enough data for type`)}var g=[24,256,65536,4294967296,BigInt("18446744073709551616")];function v(e,t,r){D(e,t,1);let n=e[t];if(r.strict===!0&&n<g[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function E(e,t,r){D(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<g[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function k(e,t,r){D(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<g[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function A(e,t,r){D(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<g[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function sr(e,t,r,n){return new c(s.uint,v(e,t+1,n),2)}function ar(e,t,r,n){return new c(s.uint,E(e,t+1,n),3)}function cr(e,t,r,n){return new c(s.uint,k(e,t+1,n),5)}function ur(e,t,r,n){return new c(s.uint,A(e,t+1,n),9)}function U(e,t){return b(e,0,t.value)}function b(e,t,r){if(r<g[0]){let n=Number(r);e.push([t|n])}else if(r<g[1]){let n=Number(r);e.push([t|24,n])}else if(r<g[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<g[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<g[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),a=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=a&255,a=a>>8,o[3]=a&255,a=a>>8,o[2]=a&255,a=a>>8,o[1]=a&255,e.push(o)}else throw new Error(`${l} encountered BigInt larger than allowable range`)}}U.encodedSize=function(t){return b.encodedSize(t.value)};b.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};U.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function dr(e,t,r,n){return new c(s.negint,-1-v(e,t+1,n),2)}function fr(e,t,r,n){return new c(s.negint,-1-E(e,t+1,n),3)}function lr(e,t,r,n){return new c(s.negint,-1-k(e,t+1,n),5)}var st=BigInt(-1),hr=BigInt(1);function pr(e,t,r,n){let o=A(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new c(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new c(s.negint,st-BigInt(o),9)}function $e(e,t){let r=t.value,n=typeof r=="bigint"?r*st-hr:r*-1-1;b(e,t.type.majorEncoded,n)}$e.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*st-hr:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};$e.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Ee(e,t,r,n){D(e,t,r+n);let o=ie(e,t+r,t+r+n);return new c(s.bytes,o,r+n)}function yr(e,t,r,n){return Ee(e,t,1,r)}function mr(e,t,r,n){return Ee(e,t,2,v(e,t+1,n))}function wr(e,t,r,n){return Ee(e,t,3,E(e,t+1,n))}function gr(e,t,r,n){return Ee(e,t,5,k(e,t+1,n))}function br(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return Ee(e,t,9,o)}function ze(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?rr(e.value):e.value),e.encodedBytes}function se(e,t){let r=ze(t);b(e,t.type.majorEncoded,r.length),e.push(r)}se.encodedSize=function(t){let r=ze(t);return b.encodedSize(r.length)+r.length};se.compareTokens=function(t,r){return _o(ze(t),ze(r))};function _o(e,t){return e.length<t.length?-1:e.length>t.length?1:ir(e,t)}function ke(e,t,r,n,o){let i=r+n;D(e,t,i);let a=new c(s.string,tr(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=ie(e,t+r,t+i)),a}function xr(e,t,r,n){return ke(e,t,1,r,n)}function vr(e,t,r,n){return ke(e,t,2,v(e,t+1,n),n)}function Er(e,t,r,n){return ke(e,t,3,E(e,t+1,n),n)}function kr(e,t,r,n){return ke(e,t,5,k(e,t+1,n),n)}function Ar(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return ke(e,t,9,o,n)}var _r=se;function ae(e,t,r,n){return new c(s.array,n,r)}function Ur(e,t,r,n){return ae(e,t,1,r)}function Tr(e,t,r,n){return ae(e,t,2,v(e,t+1,n))}function Sr(e,t,r,n){return ae(e,t,3,E(e,t+1,n))}function Br(e,t,r,n){return ae(e,t,5,k(e,t+1,n))}function Ir(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return ae(e,t,9,o)}function Nr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ae(e,t,1,1/0)}function Re(e,t){b(e,s.array.majorEncoded,t.value)}Re.compareTokens=U.compareTokens;Re.encodedSize=function(t){return b.encodedSize(t.value)};function ce(e,t,r,n){return new c(s.map,n,r)}function Cr(e,t,r,n){return ce(e,t,1,r)}function Mr(e,t,r,n){return ce(e,t,2,v(e,t+1,n))}function $r(e,t,r,n){return ce(e,t,3,E(e,t+1,n))}function zr(e,t,r,n){return ce(e,t,5,k(e,t+1,n))}function Rr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return ce(e,t,9,o)}function Or(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return ce(e,t,1,1/0)}function Oe(e,t){b(e,s.map.majorEncoded,t.value)}Oe.compareTokens=U.compareTokens;Oe.encodedSize=function(t){return b.encodedSize(t.value)};function Lr(e,t,r,n){return new c(s.tag,r,1)}function Dr(e,t,r,n){return new c(s.tag,v(e,t+1,n),2)}function Fr(e,t,r,n){return new c(s.tag,E(e,t+1,n),3)}function Vr(e,t,r,n){return new c(s.tag,k(e,t+1,n),5)}function Hr(e,t,r,n){return new c(s.tag,A(e,t+1,n),9)}function Le(e,t){b(e,s.tag.majorEncoded,t.value)}Le.compareTokens=U.compareTokens;Le.encodedSize=function(t){return b.encodedSize(t.value)};var No=20,Co=21,Mo=22,$o=23;function Pr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new c(s.null,null,1):new c(s.undefined,void 0,1)}function qr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new c(s.break,void 0,1)}function at(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new c(s.float,e,t)}function Gr(e,t,r,n){return at(ct(e,t+1),3,n)}function jr(e,t,r,n){return at(ut(e,t+1),5,n)}function Jr(e,t,r,n){return at(Qr(e,t+1),9,n)}function De(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|No]);else if(n===!0)e.push([s.float.majorEncoded|Co]);else if(n===null)e.push([s.float.majorEncoded|Mo]);else if(n===void 0)e.push([s.float.majorEncoded|$o]);else{let o,i=!1;(!r||r.float64!==!0)&&(Xr(n),o=ct(I,1),n===o||Number.isNaN(n)?(I[0]=249,e.push(I.slice(0,3)),i=!0):(Wr(n),o=ut(I,1),n===o&&(I[0]=250,e.push(I.slice(0,5)),i=!0))),i||(zo(n),o=Qr(I,1),I[0]=251,e.push(I.slice(0,9)))}}De.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Xr(n);let o=ct(I,1);if(n===o||Number.isNaN(n))return 3;if(Wr(n),o=ut(I,1),n===o)return 5}return 9};var Kr=new ArrayBuffer(9),T=new DataView(Kr,1),I=new Uint8Array(Kr,0);function Xr(e){if(e===1/0)T.setUint16(0,31744,!1);else if(e===-1/0)T.setUint16(0,64512,!1);else if(Number.isNaN(e))T.setUint16(0,32256,!1);else{T.setFloat32(0,e);let t=T.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)T.setUint16(0,31744,!1);else if(r===0)T.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?T.setUint16(0,0):o<-14?T.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):T.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ct(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Wr(e){T.setFloat32(0,e,!1)}function ut(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function zo(e){T.setFloat64(0,e,!1)}function Qr(e,t){if(e.length-t<8)throw new Error(`${l} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}De.compareTokens=U.compareTokens;function y(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Fe(e){return()=>{throw new Error(`${l} ${e}`)}}var u=[];for(let e=0;e<=23;e++)u[e]=y;u[24]=sr;u[25]=ar;u[26]=cr;u[27]=ur;u[28]=y;u[29]=y;u[30]=y;u[31]=y;for(let e=32;e<=55;e++)u[e]=y;u[56]=dr;u[57]=fr;u[58]=lr;u[59]=pr;u[60]=y;u[61]=y;u[62]=y;u[63]=y;for(let e=64;e<=87;e++)u[e]=yr;u[88]=mr;u[89]=wr;u[90]=gr;u[91]=br;u[92]=y;u[93]=y;u[94]=y;u[95]=Fe("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)u[e]=xr;u[120]=vr;u[121]=Er;u[122]=kr;u[123]=Ar;u[124]=y;u[125]=y;u[126]=y;u[127]=Fe("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)u[e]=Ur;u[152]=Tr;u[153]=Sr;u[154]=Br;u[155]=Ir;u[156]=y;u[157]=y;u[158]=y;u[159]=Nr;for(let e=160;e<=183;e++)u[e]=Cr;u[184]=Mr;u[185]=$r;u[186]=zr;u[187]=Rr;u[188]=y;u[189]=y;u[190]=y;u[191]=Or;for(let e=192;e<=215;e++)u[e]=Lr;u[216]=Dr;u[217]=Fr;u[218]=Vr;u[219]=Hr;u[220]=y;u[221]=y;u[222]=y;u[223]=y;for(let e=224;e<=243;e++)u[e]=Fe("simple values are not supported");u[244]=y;u[245]=y;u[246]=y;u[247]=Pr;u[248]=Fe("simple values are not supported");u[249]=Gr;u[250]=jr;u[251]=Jr;u[252]=y;u[253]=y;u[254]=y;u[255]=qr;var N=[];for(let e=0;e<24;e++)N[e]=new c(s.uint,e,1);for(let e=-1;e>=-24;e--)N[31-e]=new c(s.negint,e,1);N[64]=new c(s.bytes,new Uint8Array(0),1);N[96]=new c(s.string,"",1);N[128]=new c(s.array,0,1);N[160]=new c(s.map,0,1);N[244]=new c(s.false,!1,1);N[245]=new c(s.true,!0,1);N[246]=new c(s.null,null,1);function Ve(e){switch(e.type){case s.false:return R([244]);case s.true:return R([245]);case s.null:return R([246]);case s.bytes:return e.value.length?void 0:R([64]);case s.string:return e.value===""?R([96]):void 0;case s.array:return e.value===0?R([128]):void 0;case s.map:return e.value===0?R([160]):void 0;case s.uint:return e.value<24?R([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return R([31-Number(e.value)])}}var Oo={float64:!1,mapSorter:Do,quickEncodeToken:Ve};function ft(){let e=[];return e[s.uint.major]=U,e[s.negint.major]=$e,e[s.bytes.major]=se,e[s.string.major]=_r,e[s.array.major]=Re,e[s.map.major]=Oe,e[s.tag.major]=Le,e[s.float.major]=De,e}var Yr=ft(),dt=new xe,ue=class{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${it} object contains circular references`);return new ue(r,t)}},V={null:new c(s.null,null),undefined:new c(s.undefined,void 0),true:new c(s.true,!0),false:new c(s.false,!1),emptyArray:new c(s.array,0),emptyMap:new c(s.map,0)},H={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new c(s.float,e):e>=0?new c(s.uint,e):new c(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new c(s.uint,e):new c(s.negint,e)},Uint8Array(e,t,r,n){return new c(s.bytes,e)},string(e,t,r,n){return new c(s.string,e)},boolean(e,t,r,n){return e?V.true:V.false},null(e,t,r,n){return V.null},undefined(e,t,r,n){return V.undefined},ArrayBuffer(e,t,r,n){return new c(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new c(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[V.emptyArray,new c(s.break)]:V.emptyArray;n=ue.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=Ae(a,r,n);return r.addBreakTokens?[new c(s.array,e.length),o,new c(s.break)]:[new c(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),a=o?e.size:i.length;if(!a)return r.addBreakTokens===!0?[V.emptyMap,new c(s.break)]:V.emptyMap;n=ue.createCheck(n,e);let d=[],f=0;for(let h of i)d[f++]=[Ae(h,r,n),Ae(o?e.get(h):e[h],r,n)];return Lo(d,r),r.addBreakTokens?[new c(s.map,a),d,new c(s.break)]:[new c(s.map,a),d]}};H.Map=H.Object;H.Buffer=H.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))H[`${e}Array`]=H.DataView;function Ae(e,t={},r){let n=Qt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||H[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=H[n];if(!i)throw new Error(`${it} unsupported type: ${n}`);return i(e,n,t,r)}function Lo(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Do(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Yr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Zr(e,t,r,n){if(Array.isArray(t))for(let o of t)Zr(e,o,r,n);else r[t.type.major](e,t,n)}function Fo(e,t,r){let n=Ae(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),d=new xe(a);if(i(d,n,r),d.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ot(d.chunks[0])}}return dt.reset(),Zr(dt,n,t,r),dt.toBytes(!0)}function lt(e,t){return t=Object.assign({},Oo,t),Fo(e,Yr,t)}var Vo={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ht=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=N[t];if(r===void 0){let n=u[t];if(!n)throw new Error(`${l} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this.pos,o,this.options)}return this.pos+=r.encodedLength,r}},_e=Symbol.for("DONE"),He=Symbol.for("BREAK");function Ho(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ue(t,r);if(i===He){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===_e)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Po(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<e.value;a++){let d=Ue(t,r);if(d===He){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(d===_e)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof d!="string")throw new Error(`${l} non-string keys not supported (got ${typeof d})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(d)||!n&&d in o))throw new Error(`${l} found repeat map key "${d}"`);let f=Ue(t,r);if(f===_e)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(d,f):o[d]=f}return n?i:o}function Ue(e,t){if(e.done())return _e;let r=e.next();if(r.type===s.break)return He;if(r.type.terminal)return r.value;if(r.type===s.array)return Ho(r,e,t);if(r.type===s.map)return Po(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ue(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function pt(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Vo,t);let r=t.tokenizer||new ht(e,t),n=Ue(r,t);if(n===_e)throw new Error(`${l} did not find any content to decode`);if(n===He)throw new Error(`${l} got unexpected break`);if(!r.done())throw new Error(`${l} too many terminals, data makes no sense`);return n}var en=42;function Go(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=m.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new c(s.tag,en),new c(s.bytes,r)]}function jo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Jo(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Ko={float64:!0,typeEncoders:{Object:Go,undefined:jo,number:Jo}};function Xo(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return m.decode(e.subarray(1))}var tn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};tn.tags[en]=Xo;var Pe=e=>lt(e,Ko),rn=e=>pt(e,tn);var P={Null:e=>e===null,Int:e=>Number.isInteger(e),Float:e=>typeof e=="number"&&Number.isFinite(e),String:e=>typeof e=="string",Bool:e=>typeof e=="boolean",Bytes:e=>e instanceof Uint8Array,Link:e=>!P.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!P.Null(e)&&typeof e=="object"&&e.asCID!==e&&!P.List(e)&&!P.Bytes(e)},de={Int:P.Int,"CarHeader > version":e=>de.Int(e),"CarHeader > roots (anon) > valueType (anon)":P.Link,"CarHeader > roots (anon)":e=>P.List(e)&&Array.prototype.every.call(e,de["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>de["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return P.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>de["CarHeader > "+r]&&de["CarHeader > "+r](n))}},nn=de.CarHeader;var yt={SHA2_256:18,LENGTH:32,DAG_PB:112},on=16+8+8+8;async function qe(e){let t=await e.upTo(8);if(!t.length)throw new Error("Unexpected end of data");let r=q.default.decode(t);return e.seek(q.default.decode.bytes),r}async function Qo(e){let t=await e.exactly(on),r=new DataView(t.buffer,t.byteOffset,t.byteLength),n=0,o={version:2,characteristics:[r.getBigUint64(n,!0),r.getBigUint64(n+=8,!0)],dataOffset:Number(r.getBigUint64(n+=8,!0)),dataSize:Number(r.getBigUint64(n+=8,!0)),indexOffset:Number(r.getBigUint64(n+=8,!0))};return e.seek(on),o}async function Ge(e,t){let r=await qe(e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r);e.seek(r);let o=rn(n);if(!nn(o))throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let a=await Qo(e);e.seek(a.dataOffset-e.pos);let d=await Ge(e,1);return Object.assign(d,a)}async function Yo(e){let t=await e.upTo(8);q.default.decode(t);let r=q.default.decode.bytes,n=q.default.decode(t.subarray(q.default.decode.bytes)),o=q.default.decode.bytes,i=r+o+n,a=await e.exactly(i);return e.seek(i),a}async function Zo(e){let t=await e.exactly(2);if(t[0]===yt.SHA2_256&&t[1]===yt.LENGTH){let a=await e.exactly(34);e.seek(34);let d=we(a);return m.create(0,yt.DAG_PB,d)}let r=await qe(e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=await qe(e),o=await Yo(e),i=we(o);return m.create(r,n,i)}async function sn(e){let t=e.pos,r=await qe(e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await Zo(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function ei(e){let{cid:t,blockLength:r}=await sn(e),n=await e.exactly(r);return e.seek(r),{bytes:n,cid:t}}async function ti(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await sn(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function fe(e){let t=(async()=>{let r=await Ge(e);if(r.version===2){let n=e.pos-r.dataOffset;e=ni(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await ei(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await ti(e)}}}function G(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r){if(r>e.length-t)throw new Error("Unexpected end of data");return e.subarray(t,t+r)},seek(r){t+=r},get pos(){return t}}}function ri(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async a=>{r=o.length-n;let d=[o.subarray(n)];for(;r<a;){let h=await e();if(h==null)break;r<0?h.length>r&&d.push(h.subarray(-r)):d.push(h),r+=h.length}o=new Uint8Array(d.reduce((h,p)=>h+p.length,0));let f=0;for(let h of d)o.set(h,f),f+=h.length;n=0};return{async upTo(a){return o.length-n<a&&await i(a),o.subarray(n,n+Math.min(o.length-n,a))},async exactly(a){if(o.length-n<a&&await i(a),o.length-n<a)throw new Error("Unexpected end of data");return o.subarray(n,n+a)},seek(a){t+=a,n+=a},get pos(){return t}}}function le(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return ri(r)}function ni(e,t){let r=0;return{async upTo(n){let o=await e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},async exactly(n){let o=await e.exactly(n);if(o.length+r>t)throw new Error("Unexpected end of data");return o},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var K=class{constructor(t,r){this._header=t,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(t){return this._keys.indexOf(t.toString())>-1}async get(t){let r=this._keys.indexOf(t.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let t of this._blocks)yield t}async*cids(){for(let t of this._blocks)yield t.cid}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return an(G(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return an(le(t))}};async function an(e){let t=fe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new K(r,n)}var X=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return cn(G(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return cn(le(t))}};async function cn(e){let t=fe(e),{version:r,roots:n}=await t.header();return new X(r,n,t.blocksIndex())}var je=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},W=class extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await un(t);return new W(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await dn(t);return new W(r,n,o)}},Q=class extends je{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await un(t);return new Q(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await dn(t);return new Q(r,n,o)}};async function un(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return fn(G(e))}async function dn(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return fn(le(e))}async function fn(e){let t=fe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var mt=Ne(Ce(),1);function wt(e){let t=Pe({version:1,roots:e}),r=mt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function ln(e){return{async setRoots(t){let r=wt(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(mt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function Je(){}function hn(){let e=[],t=null,r=Je,n=!1,o=null,i=Je,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=Je,h()}})),t),d={write(h){e.push(h);let p=a();return i(),p},async end(){n=!0;let h=a();i(),await h}},f={async next(){let h=e.shift();return h?(e.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(p=>{i=()=>(o=null,i=Je,p(f.next()))})),o)}};return{writer:d,iterator:f}}var Y=class{constructor(t,r){this._encoder=r,this._mutex=r.setRoots(t),this._ended=!1}async put(t){if(!(t.bytes instanceof Uint8Array)||!t.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=m.asCID(t.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:t.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}static create(t){t=oi(t);let{encoder:r,iterator:n}=pn(),o=new Y(t,r),i=new Ke(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=pn();t.setRoots=()=>Promise.resolve();let n=new Y([],t),o=new Ke(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=G(t);await Ge(n);let o=wt(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return t.set(o,0),t}},Ke=class{constructor(t){this._iterator=t}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function pn(){let e=hn(),{writer:t,iterator:r}=e;return{encoder:ln(t),iterator:r}}function oi(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=m.asCID(e);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let t=[];for(let r of e){let n=m.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var gt=Ne(yn(),1);var he=class{constructor(t,r,n,o,i){this._version=t,this._path=r,this._roots=n,this._index=o,this._order=i,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(t){return this._index.has(t.toString())}async get(t){let r=this._index.get(t.toString());if(!r)return;this._fd||(this._fd=await gt.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return K.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(m.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield m.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await X.fromIterable((void 0).from(gt.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:d}of r){let f=i.toString();n.set(f,{blockLength:a,blockOffset:d}),o.push(f)}return new he(r.version,t,await r.getRoots(),n,o)}};var _t={};Ut(_t,{addBlock:()=>bn,addRoot:()=>gn,blockLength:()=>ai,calculateHeaderLength:()=>kt,close:()=>xn,createWriter:()=>fi,estimateHeaderLength:()=>di,headerLength:()=>At,resizeHeader:()=>Et});var Te=Ne(Ce(),1);var ii=ft(),si={float64:!1,quickEncodeToken:Ve};function bt(e,t=ii,r=si){if(Array.isArray(e)){let n=0;for(let o of e)n+=bt(o,t,r);return n}else{let n=t[e.type.major];if(n.encodedSize===void 0||typeof n.encodedSize!="function")throw new Error(`Encoder for ${e.type.name} does not have an encodedSize()`);return n.encodedSize(e,r)}}var vt=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return gn(this,t,r),this}write(t){return bn(this,t),this}close(t){return xn(this,t)}},gn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:d}=e;e.roots.push(t);let f=At(e);if(f>i)if(f-i+a<o.byteLength)if(n)Et(e,f);else throw d.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
|
|
3
|
-
However there is a space in the buffer and you could call addRoot(root, { resize: root }) to resize header to make a space for this root.`);else throw
|
|
4
|
-
You can use close({ resize: true }) to resize header`)},
|
|
2
|
+
"use strict";var IpldCar=(()=>{var Un=Object.create;var Re=Object.defineProperty;var Sn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,Cn=Object.prototype.hasOwnProperty;var ge=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Rt=(e,t)=>{for(var r in t)Re(e,r,{get:t[r],enumerable:!0})},Mt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bn(t))!Cn.call(e,o)&&o!==r&&Re(e,o,{get:()=>t[o],enumerable:!(n=Sn(t,o))||n.enumerable});return e};var Me=(e,t,r)=>(r=e!=null?Un(In(e)):{},Mt(t||!e||!e.__esModule?Re(r,"default",{value:e,enumerable:!0}):r,e)),Nn=e=>Mt(Re({},"__esModule",{value:!0}),e);var tn=ge((Ks,en)=>{en.exports=vt;var Zr=128,Po=127,qo=~Po,Go=Math.pow(2,31);function vt(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw vt.bytes=0,new RangeError("Could not encode varint");t=t||[],r=r||0;for(var n=r;e>=Go;)t[r++]=e&255|Zr,e/=128;for(;e&qo;)t[r++]=e&255|Zr,e>>>=7;return t[r]=e|0,vt.bytes=r-n+1,t}});var on=ge((Xs,nn)=>{nn.exports=Et;var jo=128,rn=127;function Et(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c||o>49)throw Et.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&rn)<<o:(a&rn)*Math.pow(2,o),o+=7}while(a>=jo);return Et.bytes=i-n,r}});var an=ge((Qs,sn)=>{var Jo=Math.pow(2,7),Ko=Math.pow(2,14),Xo=Math.pow(2,21),Qo=Math.pow(2,28),Wo=Math.pow(2,35),Yo=Math.pow(2,42),Zo=Math.pow(2,49),ei=Math.pow(2,56),ti=Math.pow(2,63);sn.exports=function(e){return e<Jo?1:e<Ko?2:e<Xo?3:e<Qo?4:e<Wo?5:e<Yo?6:e<Zo?7:e<ei?8:e<ti?9:10}});var Ke=ge((Ws,cn)=>{cn.exports={encode:tn(),decode:on(),encodingLength:an()}});var xn=ge(()=>{});var xi={};Rt(xi,{CarBlockIterator:()=>Z,CarBufferReader:()=>me,CarBufferWriter:()=>Nt,CarCIDIterator:()=>ee,CarIndexedReader:()=>we,CarIndexer:()=>Y,CarReader:()=>W,CarWriter:()=>te});var Rn=Ot,$t=128,Mn=127,$n=~Mn,zn=Math.pow(2,31);function Ot(e,t,r){t=t||[],r=r||0;for(var n=r;e>=zn;)t[r++]=e&255|$t,e/=128;for(;e&$n;)t[r++]=e&255|$t,e>>>=7;return t[r]=e|0,Ot.bytes=r-n+1,t}var On=rt,Dn=128,zt=127;function rt(e,n){var r=0,n=n||0,o=0,i=n,a,c=e.length;do{if(i>=c)throw rt.bytes=0,new RangeError("Could not decode varint");a=e[i++],r+=o<28?(a&zt)<<o:(a&zt)*Math.pow(2,o),o+=7}while(a>=Dn);return rt.bytes=i-n,r}var Ln=Math.pow(2,7),Fn=Math.pow(2,14),Hn=Math.pow(2,21),Vn=Math.pow(2,28),Pn=Math.pow(2,35),qn=Math.pow(2,42),Gn=Math.pow(2,49),jn=Math.pow(2,56),Jn=Math.pow(2,63),Kn=function(e){return e<Ln?1:e<Fn?2:e<Hn?3:e<Vn?4:e<Pn?5:e<qn?6:e<Gn?7:e<jn?8:e<Jn?9:10},Xn={encode:Rn,decode:On,encodingLength:Kn},Qn=Xn,be=Qn;var xe=(e,t=0)=>[be.decode(e,t),be.decode.bytes],ne=(e,t,r=0)=>(be.encode(e,t,r),t),oe=e=>be.encodingLength(e);var Ai=new Uint8Array(0);var Lt=(e,t)=>{if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},ie=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var Ft=(e,t)=>{let r=t.byteLength,n=oe(e),o=n+oe(r),i=new Uint8Array(o+r);return ne(e,i,0),ne(r,i,n),i.set(t,o),new se(e,r,t,i)},V=e=>{let t=ie(e),[r,n]=xe(t),[o,i]=xe(t.subarray(n)),a=t.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new se(r,o,a,t)},Ht=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Lt(e.bytes,r.bytes)}},se=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Wn(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),a=i.charCodeAt(0);if(r[a]!==255)throw new TypeError(i+" is ambiguous");r[a]=o}var c=e.length,f=e.charAt(0),h=Math.log(c)/Math.log(256),y=Math.log(256)/Math.log(c);function re(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var x=0,X=0,S=0,N=w.length;S!==N&&w[S]===0;)S++,x++;for(var R=(N-S)*y+1>>>0,_=new Uint8Array(R);S!==N;){for(var M=w[S],H=0,B=R-1;(M!==0||H<X)&&B!==-1;B--,H++)M+=256*_[B]>>>0,_[B]=M%c>>>0,M=M/c>>>0;if(M!==0)throw new Error("Non-zero carry");X=H,S++}for(var D=R-X;D!==R&&_[D]===0;)D++;for(var Ne=f.repeat(x);D<R;++D)Ne+=e.charAt(_[D]);return Ne}function Ce(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var x=0;if(w[x]!==" "){for(var X=0,S=0;w[x]===f;)X++,x++;for(var N=(w.length-x)*h+1>>>0,R=new Uint8Array(N);w[x];){var _=r[w.charCodeAt(x)];if(_===255)return;for(var M=0,H=N-1;(_!==0||M<S)&&H!==-1;H--,M++)_+=c*R[H]>>>0,R[H]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=M,x++}if(w[x]!==" "){for(var B=N-S;B!==N&&R[B]===0;)B++;for(var D=new Uint8Array(X+(N-B)),Ne=X;B!==N;)D[Ne++]=R[B++];return D}}}function Tn(w){var x=Ce(w);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:re,decodeUnsafe:Ce,decode:Tn}}var Yn=Wn,Zn=Yn,Vt=Zn;var ot=class{constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},it=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Pt(this,t)}},st=class{constructor(t){this.decoders=t}or(t){return Pt(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Pt=(e,t)=>new st({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),at=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ot(t,r,n),this.decoder=new it(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},qt=({name:e,prefix:t,encode:r,decode:n})=>new at(e,t,r,n),ct=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Vt(r,t);return qt({prefix:e,name:t,encode:n,decode:i=>ie(o(i))})},eo=(e,t,r,n)=>{let o={};for(let y=0;y<t.length;++y)o[t[y]]=y;let i=e.length;for(;e[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),c=0,f=0,h=0;for(let y=0;y<i;++y){let re=o[e[y]];if(re===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|re,c+=r,c>=8&&(c-=8,a[h++]=255&f>>c)}if(c>=r||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return a},to=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",a=0,c=0;for(let f=0;f<e.length;++f)for(c=c<<8|e[f],a+=8;a>r;)a-=r,i+=t[o&c>>a];if(a&&(i+=t[o&c<<r-a]),n)for(;i.length*r&7;)i+="=";return i},$=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>qt({prefix:t,name:e,encode(o){return to(o,n,r)},decode(o){return eo(o,n,r,e)}});var L=ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ni=ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ve=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$i=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zi=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Oi=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Di=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Li=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Fi=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Hi=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vi=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gt=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return no(r,ut(e),t||L.encoder);default:return oo(r,ut(e),t||ve.encoder)}};var jt=new WeakMap,ut=e=>{let t=jt.get(e);if(t==null){let r=new Map;return jt.set(e,r),r}return t},p=class{constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==io)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return p.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ft(t,r);return p.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return p.equals(this,t)}static equals(t,r){let n=r;return n&&t.code===n.code&&t.version===n.version&&Ht(t.multihash,n.multihash)}toString(t){return Gt(this,t)}toJSON(){return{"/":Gt(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof p)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new p(n,o,i,a||Jt(n,o,i.bytes))}else if(r[so]===!0){let{version:n,multihash:o,code:i}=r,a=V(o);return p.create(n,i,a)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ee)throw new Error(`Version 0 CID must use dag-pb (code: ${Ee}) block encoding`);return new p(t,r,n,n.bytes)}case 1:{let o=Jt(t,r,n.bytes);return new p(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return p.create(0,Ee,t)}static createV1(t,r){return p.create(1,t,r)}static decode(t){let[r,n]=p.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=p.inspectBytes(t),n=r.size-r.multihashSize,o=ie(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),a=new se(r.multihashCode,r.digestSize,i,o);return[r.version===0?p.createV0(a):p.createV1(r.codec,a),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[re,Ce]=xe(t.subarray(r));return r+=Ce,re},o=n(),i=Ee;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,c=n(),f=n(),h=r+f,y=h-a;return{version:o,codec:i,multihashCode:c,digestSize:f,multihashSize:y,size:h}}static parse(t,r){let[n,o]=ro(t,r),i=p.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ut(i).set(n,t),i}},ro=(e,t)=>{switch(e[0]){case"Q":{let r=t||L;return[L.prefix,r.decode(`${L.prefix}${e}`)]}case L.prefix:{let r=t||L;return[L.prefix,r.decode(e)]}case ve.prefix:{let r=t||ve;return[ve.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},no=(e,t,r)=>{let{prefix:n}=r;if(n!==L.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o},oo=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},Ee=112,io=18,Jt=(e,t,r)=>{let n=oe(e),o=n+oe(t),i=new Uint8Array(o+r.byteLength);return ne(e,i,0),ne(t,i,n),i.set(r,o),i},so=Symbol.for("@ipld/js-cid/CID");var ao=["string","number","bigint","symbol"],co=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Kt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(ao.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(uo(e))return"Buffer";let r=fo(e);return r||"Object"}function uo(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function fo(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(co.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var u=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ae=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",lo=new TextDecoder,ho=new TextEncoder;function $e(e){return ae&&globalThis.Buffer.isBuffer(e)}function dt(e){return e instanceof Uint8Array?$e(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Yt=ae?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Qt(e,t,r):(e,t,r)=>r-t>64?lo.decode(e.subarray(t,r)):Qt(e,t,r),Zt=ae?e=>e.length>64?globalThis.Buffer.from(e):Xt(e):e=>e.length>64?ho.encode(e):Xt(e),z=e=>Uint8Array.from(e),ce=ae?(e,t,r)=>$e(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),er=ae?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),dt(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},tr=ae?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function rr(e,t){if($e(e)&&$e(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Xt(e,t=1/0){let r,n=e.length,o=null,i=[];for(let a=0;a<n;++a){if(r=e.charCodeAt(a),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(a+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Qt(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=r){let c,f,h,y;switch(a){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(y=(o&31)<<6|c&63,y>127&&(i=y));break;case 3:c=e[t+1],f=e[t+2],(c&192)===128&&(f&192)===128&&(y=(o&15)<<12|(c&63)<<6|f&63,y>2047&&(y<55296||y>57343)&&(i=y));break;case 4:c=e[t+1],f=e[t+2],h=e[t+3],(c&192)===128&&(f&192)===128&&(h&192)===128&&(y=(o&15)<<18|(c&63)<<12|(f&63)<<6|h&63,y>65535&&y<1114112&&(i=y))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=a}return po(n)}var Wt=4096;function po(e){let t=e.length;if(t<=Wt)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Wt));return r}var yo=256,ke=class{constructor(t=yo){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=tr(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=ce(n,0,this.cursor)}else r=er(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",ft="CBOR encode error:",Ae=[];Ae[23]=1;Ae[24]=2;Ae[25]=3;Ae[26]=5;Ae[27]=9;function F(e,t,r){if(e.length-t<r)throw new Error(`${l} not enough data for type`)}var g=[24,256,65536,4294967296,BigInt("18446744073709551616")];function v(e,t,r){F(e,t,1);let n=e[t];if(r.strict===!0&&n<g[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function E(e,t,r){F(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<g[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function k(e,t,r){F(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<g[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function A(e,t,r){F(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<g[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function nr(e,t,r,n){return new u(s.uint,v(e,t+1,n),2)}function or(e,t,r,n){return new u(s.uint,E(e,t+1,n),3)}function ir(e,t,r,n){return new u(s.uint,k(e,t+1,n),5)}function sr(e,t,r,n){return new u(s.uint,A(e,t+1,n),9)}function T(e,t){return b(e,0,t.value)}function b(e,t,r){if(r<g[0]){let n=Number(r);e.push([t|n])}else if(r<g[1]){let n=Number(r);e.push([t|24,n])}else if(r<g[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<g[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<g[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),a=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=a&255,a=a>>8,o[3]=a&255,a=a>>8,o[2]=a&255,a=a>>8,o[1]=a&255,e.push(o)}else throw new Error(`${l} encountered BigInt larger than allowable range`)}}T.encodedSize=function(t){return b.encodedSize(t.value)};b.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};T.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function ar(e,t,r,n){return new u(s.negint,-1-v(e,t+1,n),2)}function cr(e,t,r,n){return new u(s.negint,-1-E(e,t+1,n),3)}function ur(e,t,r,n){return new u(s.negint,-1-k(e,t+1,n),5)}var lt=BigInt(-1),dr=BigInt(1);function fr(e,t,r,n){let o=A(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new u(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new u(s.negint,lt-BigInt(o),9)}function ze(e,t){let r=t.value,n=typeof r=="bigint"?r*lt-dr:r*-1-1;b(e,t.type.majorEncoded,n)}ze.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*lt-dr:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};ze.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function _e(e,t,r,n){F(e,t,r+n);let o=ce(e,t+r,t+r+n);return new u(s.bytes,o,r+n)}function lr(e,t,r,n){return _e(e,t,1,r)}function hr(e,t,r,n){return _e(e,t,2,v(e,t+1,n))}function pr(e,t,r,n){return _e(e,t,3,E(e,t+1,n))}function yr(e,t,r,n){return _e(e,t,5,k(e,t+1,n))}function mr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return _e(e,t,9,o)}function Oe(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?Zt(e.value):e.value),e.encodedBytes}function ue(e,t){let r=Oe(t);b(e,t.type.majorEncoded,r.length),e.push(r)}ue.encodedSize=function(t){let r=Oe(t);return b.encodedSize(r.length)+r.length};ue.compareTokens=function(t,r){return wo(Oe(t),Oe(r))};function wo(e,t){return e.length<t.length?-1:e.length>t.length?1:rr(e,t)}function Te(e,t,r,n,o){let i=r+n;F(e,t,i);let a=new u(s.string,Yt(e,t+r,t+i),i);return o.retainStringBytes===!0&&(a.byteValue=ce(e,t+r,t+i)),a}function wr(e,t,r,n){return Te(e,t,1,r,n)}function gr(e,t,r,n){return Te(e,t,2,v(e,t+1,n),n)}function br(e,t,r,n){return Te(e,t,3,E(e,t+1,n),n)}function xr(e,t,r,n){return Te(e,t,5,k(e,t+1,n),n)}function vr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return Te(e,t,9,o,n)}var Er=ue;function de(e,t,r,n){return new u(s.array,n,r)}function kr(e,t,r,n){return de(e,t,1,r)}function Ar(e,t,r,n){return de(e,t,2,v(e,t+1,n))}function _r(e,t,r,n){return de(e,t,3,E(e,t+1,n))}function Tr(e,t,r,n){return de(e,t,5,k(e,t+1,n))}function Ur(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return de(e,t,9,o)}function Sr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return de(e,t,1,1/0)}function De(e,t){b(e,s.array.majorEncoded,t.value)}De.compareTokens=T.compareTokens;De.encodedSize=function(t){return b.encodedSize(t.value)};function fe(e,t,r,n){return new u(s.map,n,r)}function Br(e,t,r,n){return fe(e,t,1,r)}function Ir(e,t,r,n){return fe(e,t,2,v(e,t+1,n))}function Cr(e,t,r,n){return fe(e,t,3,E(e,t+1,n))}function Nr(e,t,r,n){return fe(e,t,5,k(e,t+1,n))}function Rr(e,t,r,n){let o=A(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return fe(e,t,9,o)}function Mr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return fe(e,t,1,1/0)}function Le(e,t){b(e,s.map.majorEncoded,t.value)}Le.compareTokens=T.compareTokens;Le.encodedSize=function(t){return b.encodedSize(t.value)};function $r(e,t,r,n){return new u(s.tag,r,1)}function zr(e,t,r,n){return new u(s.tag,v(e,t+1,n),2)}function Or(e,t,r,n){return new u(s.tag,E(e,t+1,n),3)}function Dr(e,t,r,n){return new u(s.tag,k(e,t+1,n),5)}function Lr(e,t,r,n){return new u(s.tag,A(e,t+1,n),9)}function Fe(e,t){b(e,s.tag.majorEncoded,t.value)}Fe.compareTokens=T.compareTokens;Fe.encodedSize=function(t){return b.encodedSize(t.value)};var ko=20,Ao=21,_o=22,To=23;function Fr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new u(s.null,null,1):new u(s.undefined,void 0,1)}function Hr(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new u(s.break,void 0,1)}function ht(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new u(s.float,e,t)}function Vr(e,t,r,n){return ht(pt(e,t+1),3,n)}function Pr(e,t,r,n){return ht(yt(e,t+1),5,n)}function qr(e,t,r,n){return ht(Kr(e,t+1),9,n)}function He(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|ko]);else if(n===!0)e.push([s.float.majorEncoded|Ao]);else if(n===null)e.push([s.float.majorEncoded|_o]);else if(n===void 0)e.push([s.float.majorEncoded|To]);else{let o,i=!1;(!r||r.float64!==!0)&&(jr(n),o=pt(I,1),n===o||Number.isNaN(n)?(I[0]=249,e.push(I.slice(0,3)),i=!0):(Jr(n),o=yt(I,1),n===o&&(I[0]=250,e.push(I.slice(0,5)),i=!0))),i||(Uo(n),o=Kr(I,1),I[0]=251,e.push(I.slice(0,9)))}}He.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){jr(n);let o=pt(I,1);if(n===o||Number.isNaN(n))return 3;if(Jr(n),o=yt(I,1),n===o)return 5}return 9};var Gr=new ArrayBuffer(9),U=new DataView(Gr,1),I=new Uint8Array(Gr,0);function jr(e){if(e===1/0)U.setUint16(0,31744,!1);else if(e===-1/0)U.setUint16(0,64512,!1);else if(Number.isNaN(e))U.setUint16(0,32256,!1);else{U.setFloat32(0,e);let t=U.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)U.setUint16(0,31744,!1);else if(r===0)U.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?U.setUint16(0,0):o<-14?U.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):U.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function pt(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Jr(e){U.setFloat32(0,e,!1)}function yt(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Uo(e){U.setFloat64(0,e,!1)}function Kr(e,t){if(e.length-t<8)throw new Error(`${l} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}He.compareTokens=T.compareTokens;function m(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ve(e){return()=>{throw new Error(`${l} ${e}`)}}var d=[];for(let e=0;e<=23;e++)d[e]=m;d[24]=nr;d[25]=or;d[26]=ir;d[27]=sr;d[28]=m;d[29]=m;d[30]=m;d[31]=m;for(let e=32;e<=55;e++)d[e]=m;d[56]=ar;d[57]=cr;d[58]=ur;d[59]=fr;d[60]=m;d[61]=m;d[62]=m;d[63]=m;for(let e=64;e<=87;e++)d[e]=lr;d[88]=hr;d[89]=pr;d[90]=yr;d[91]=mr;d[92]=m;d[93]=m;d[94]=m;d[95]=Ve("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)d[e]=wr;d[120]=gr;d[121]=br;d[122]=xr;d[123]=vr;d[124]=m;d[125]=m;d[126]=m;d[127]=Ve("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)d[e]=kr;d[152]=Ar;d[153]=_r;d[154]=Tr;d[155]=Ur;d[156]=m;d[157]=m;d[158]=m;d[159]=Sr;for(let e=160;e<=183;e++)d[e]=Br;d[184]=Ir;d[185]=Cr;d[186]=Nr;d[187]=Rr;d[188]=m;d[189]=m;d[190]=m;d[191]=Mr;for(let e=192;e<=215;e++)d[e]=$r;d[216]=zr;d[217]=Or;d[218]=Dr;d[219]=Lr;d[220]=m;d[221]=m;d[222]=m;d[223]=m;for(let e=224;e<=243;e++)d[e]=Ve("simple values are not supported");d[244]=m;d[245]=m;d[246]=m;d[247]=Fr;d[248]=Ve("simple values are not supported");d[249]=Vr;d[250]=Pr;d[251]=qr;d[252]=m;d[253]=m;d[254]=m;d[255]=Hr;var C=[];for(let e=0;e<24;e++)C[e]=new u(s.uint,e,1);for(let e=-1;e>=-24;e--)C[31-e]=new u(s.negint,e,1);C[64]=new u(s.bytes,new Uint8Array(0),1);C[96]=new u(s.string,"",1);C[128]=new u(s.array,0,1);C[160]=new u(s.map,0,1);C[244]=new u(s.false,!1,1);C[245]=new u(s.true,!0,1);C[246]=new u(s.null,null,1);function Pe(e){switch(e.type){case s.false:return z([244]);case s.true:return z([245]);case s.null:return z([246]);case s.bytes:return e.value.length?void 0:z([64]);case s.string:return e.value===""?z([96]):void 0;case s.array:return e.value===0?z([128]):void 0;case s.map:return e.value===0?z([160]):void 0;case s.uint:return e.value<24?z([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return z([31-Number(e.value)])}}var Bo={float64:!1,mapSorter:Co,quickEncodeToken:Pe};function wt(){let e=[];return e[s.uint.major]=T,e[s.negint.major]=ze,e[s.bytes.major]=ue,e[s.string.major]=Er,e[s.array.major]=De,e[s.map.major]=Le,e[s.tag.major]=Fe,e[s.float.major]=He,e}var Xr=wt(),mt=new ke,le=class{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${ft} object contains circular references`);return new le(r,t)}},P={null:new u(s.null,null),undefined:new u(s.undefined,void 0),true:new u(s.true,!0),false:new u(s.false,!1),emptyArray:new u(s.array,0),emptyMap:new u(s.map,0)},q={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new u(s.float,e):e>=0?new u(s.uint,e):new u(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new u(s.uint,e):new u(s.negint,e)},Uint8Array(e,t,r,n){return new u(s.bytes,e)},string(e,t,r,n){return new u(s.string,e)},boolean(e,t,r,n){return e?P.true:P.false},null(e,t,r,n){return P.null},undefined(e,t,r,n){return P.undefined},ArrayBuffer(e,t,r,n){return new u(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new u(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[P.emptyArray,new u(s.break)]:P.emptyArray;n=le.createCheck(n,e);let o=[],i=0;for(let a of e)o[i++]=Ue(a,r,n);return r.addBreakTokens?[new u(s.array,e.length),o,new u(s.break)]:[new u(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),a=o?e.size:i.length;if(!a)return r.addBreakTokens===!0?[P.emptyMap,new u(s.break)]:P.emptyMap;n=le.createCheck(n,e);let c=[],f=0;for(let h of i)c[f++]=[Ue(h,r,n),Ue(o?e.get(h):e[h],r,n)];return Io(c,r),r.addBreakTokens?[new u(s.map,a),c,new u(s.break)]:[new u(s.map,a),c]}};q.Map=q.Object;q.Buffer=q.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))q[`${e}Array`]=q.DataView;function Ue(e,t={},r){let n=Kt(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||q[n];if(typeof o=="function"){let a=o(e,n,t,r);if(a!=null)return a}let i=q[n];if(!i)throw new Error(`${ft} unsupported type: ${n}`);return i(e,n,t,r)}function Io(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Co(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Xr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Qr(e,t,r,n){if(Array.isArray(t))for(let o of t)Qr(e,o,r,n);else r[t.type.major](e,t,n)}function No(e,t,r){let n=Ue(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),c=new ke(a);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return dt(c.chunks[0])}}return mt.reset(),Qr(mt,n,t,r),mt.toBytes(!0)}function gt(e,t){return t=Object.assign({},Bo,t),No(e,Xr,t)}var Ro={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},bt=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=C[t];if(r===void 0){let n=d[t];if(!n)throw new Error(`${l} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this.pos,o,this.options)}return this.pos+=r.encodedLength,r}},Se=Symbol.for("DONE"),qe=Symbol.for("BREAK");function Mo(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Be(t,r);if(i===qe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===Se)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function $o(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=Be(t,r);if(c===qe){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(c===Se)throw new Error(`${l} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${l} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${l} found repeat map key "${c}"`);let f=Be(t,r);if(f===Se)throw new Error(`${l} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?i.set(c,f):o[c]=f}return n?i:o}function Be(e,t){if(e.done())return Se;let r=e.next();if(r.type===s.break)return qe;if(r.type.terminal)return r.value;if(r.type===s.array)return Mo(r,e,t);if(r.type===s.map)return $o(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Be(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function xt(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Ro,t);let r=t.tokenizer||new bt(e,t),n=Be(r,t);if(n===Se)throw new Error(`${l} did not find any content to decode`);if(n===qe)throw new Error(`${l} got unexpected break`);if(!r.done())throw new Error(`${l} too many terminals, data makes no sense`);return n}var Wr=42;function Oo(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=p.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new u(s.tag,Wr),new u(s.bytes,r)]}function Do(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Lo(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Fo={float64:!0,typeEncoders:{Object:Oo,undefined:Do,number:Lo}};function Ho(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return p.decode(e.subarray(1))}var Yr={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Yr.tags[Wr]=Ho;var Ge=e=>gt(e,Fo),je=e=>xt(e,Yr);var G={Null:e=>e===null,Int:e=>Number.isInteger(e),Float:e=>typeof e=="number"&&Number.isFinite(e),String:e=>typeof e=="string",Bool:e=>typeof e=="boolean",Bytes:e=>e instanceof Uint8Array,Link:e=>!G.Null(e)&&typeof e=="object"&&e.asCID===e,List:e=>Array.isArray(e),Map:e=>!G.Null(e)&&typeof e=="object"&&e.asCID!==e&&!G.List(e)&&!G.Bytes(e)},he={Int:G.Int,"CarHeader > version":e=>he.Int(e),"CarHeader > roots (anon) > valueType (anon)":G.Link,"CarHeader > roots (anon)":e=>G.List(e)&&Array.prototype.every.call(e,he["CarHeader > roots (anon) > valueType (anon)"]),"CarHeader > roots":e=>he["CarHeader > roots (anon)"](e),CarHeader:e=>{let t=e&&Object.keys(e);return G.Map(e)&&["version"].every(r=>t.includes(r))&&Object.entries(e).every(([r,n])=>he["CarHeader > "+r]&&he["CarHeader > "+r](n))}},Je=he.CarHeader;var j=Me(Ke(),1),J={SHA2_256:18,LENGTH:32,DAG_PB:112},Xe=16+8+8+8;function O(e,t){if(!e.length)throw new Error("Unexpected end of data");let r=j.default.decode(e);return t.seek(j.default.decode.bytes),r}function Qe(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0;return{version:2,characteristics:[t.getBigUint64(r,!0),t.getBigUint64(r+=8,!0)],dataOffset:Number(t.getBigUint64(r+=8,!0)),dataSize:Number(t.getBigUint64(r+=8,!0)),indexOffset:Number(t.getBigUint64(r+=8,!0))}}function We(e){j.default.decode(e);let t=j.default.decode.bytes,r=j.default.decode(e.subarray(j.default.decode.bytes)),n=j.default.decode.bytes;return t+n+r}async function Ye(e,t){let r=O(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await e.exactly(r,!0),o=je(n);if(!Je(o))throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let a=Qe(await e.exactly(Xe,!0));e.seek(a.dataOffset-e.pos);let c=await Ye(e,1);return Object.assign(c,a)}async function ri(e){let t=await e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=await e.exactly(34,!0),c=V(a);return p.create(0,J.DAG_PB,c)}let r=O(await e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=O(await e.upTo(8),e),o=await e.exactly(We(await e.upTo(8)),!0),i=V(o);return p.create(r,n,i)}async function un(e){let t=e.pos,r=O(await e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=await ri(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}async function ni(e){let{cid:t,blockLength:r}=await un(e);return{bytes:await e.exactly(r,!0),cid:t}}async function oi(e){let t=e.pos,{cid:r,length:n,blockLength:o}=await un(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function pe(e){let t=(async()=>{let r=await Ye(e);if(r.version===2){let n=e.pos-r.dataOffset;e=si(e,r.dataSize-n)}return r})();return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await ni(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await oi(e)}}}function K(e){let t=0;return{async upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},async exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function ii(e){let t=0,r=0,n=0,o=new Uint8Array(0),i=async a=>{r=o.length-n;let c=[o.subarray(n)];for(;r<a;){let h=await e();if(h==null)break;r<0?h.length>r&&c.push(h.subarray(-r)):c.push(h),r+=h.length}o=new Uint8Array(c.reduce((h,y)=>h+y.length,0));let f=0;for(let h of c)o.set(h,f),f+=h.length;n=0};return{async upTo(a){return o.length-n<a&&await i(a),o.subarray(n,n+Math.min(o.length-n,a))},async exactly(a,c=!1){if(o.length-n<a&&await i(a),o.length-n<a)throw new Error("Unexpected end of data");let f=o.subarray(n,n+a);return c&&(t+=a,n+=a),f},seek(a){t+=a,n+=a},get pos(){return t}}}function ye(e){let t=e[Symbol.asyncIterator]();async function r(){let n=await t.next();return n.done?null:n.value}return ii(r)}function si(e,t){let r=0;return{async upTo(n){let o=await e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},async exactly(n,o=!1){let i=await e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var W=class{constructor(t,r){this._header=t,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(t){return this._keys.indexOf(t.toString())>-1}async get(t){let r=this._keys.indexOf(t.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let t of this._blocks)yield t}async*cids(){for(let t of this._blocks)yield t.cid}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return dn(K(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return dn(ye(t))}};async function dn(e){let t=pe(e),r=await t.header(),n=[];for await(let o of t.blocks())n.push(o);return new W(r,n)}function fn(e,t){let r=O(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=e.exactly(r,!0),o=je(n);if(!Je(o))throw new Error("Invalid CAR header format");if(o.version!==1&&o.version!==2||t!==void 0&&o.version!==t)throw new Error(`Invalid CAR version: ${o.version}${t!==void 0?` (expected ${t})`:""}`);let i=Array.isArray(o.roots);if(o.version===1&&!i||o.version===2&&i)throw new Error("Invalid CAR header format");if(o.version===1)return o;let a=Qe(e.exactly(Xe,!0));e.seek(a.dataOffset-e.pos);let c=fn(e,1);return Object.assign(c,a)}function ai(e){let t=e.exactly(2,!1);if(t[0]===J.SHA2_256&&t[1]===J.LENGTH){let a=e.exactly(34,!0),c=V(a);return p.create(0,J.DAG_PB,c)}let r=O(e.upTo(8),e);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=O(e.upTo(8),e),o=e.exactly(We(e.upTo(8)),!0),i=V(o);return p.create(r,n,i)}function ci(e){let t=e.pos,r=O(e.upTo(8),e);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;let n=ai(e),o=r-Number(e.pos-t);return{cid:n,length:r,blockLength:o}}function ln(e){let t=ui(e),r=fn(t);if(r.version===2){let o=t.pos-r.dataOffset;t=di(t,r.dataSize-o)}let n=[];for(;t.upTo(8).length>0;){let{cid:o,blockLength:i}=ci(t);n.push({cid:o,bytes:t.exactly(i,!0)})}return{header:r,blocks:n}}function ui(e){let t=0;return{upTo(r){return e.subarray(t,t+Math.min(r,e.length-t))},exactly(r,n=!1){if(r>e.length-t)throw new Error("Unexpected end of data");let o=e.subarray(t,t+r);return n&&(t+=r),o},seek(r){t+=r},get pos(){return t}}}function di(e,t){let r=0;return{upTo(n){let o=e.upTo(n);return o.length+r>t&&(o=o.subarray(0,t-r)),o},exactly(n,o=!1){let i=e.exactly(n,o);if(i.length+r>t)throw new Error("Unexpected end of data");return o&&(r+=n),i},seek(n){r+=n,e.seek(n)},get pos(){return e.pos}}}var me=class{constructor(t,r){this._header=t,this._blocks=r,this._cids=void 0}get version(){return this._header.version}getRoots(){return this._header.roots}has(t){return this._blocks.some(r=>r.cid.equals(t))}get(t){return this._blocks.find(r=>r.cid.equals(t))}blocks(){return this._blocks}cids(){return this._cids||(this._cids=this._blocks.map(t=>t.cid)),this._cids}static fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");let{header:r,blocks:n}=ln(t);return new me(r,n)}};var Y=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(t){if(!(t instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return hn(K(t))}static async fromIterable(t){if(!t||typeof t[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return hn(ye(t))}};async function hn(e){let t=pe(e),{version:r,roots:n}=await t.header();return new Y(r,n,t.blocksIndex())}var Ze=class{constructor(t,r,n){this._version=t,this._roots=r,this._iterable=n,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}},Z=class extends Ze{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await pn(t);return new Z(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await yn(t);return new Z(r,n,o)}},ee=class extends Ze{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");this._decoded=!0;let t=this._iterable[Symbol.asyncIterator]();return{async next(){let r=await t.next();return r.done?r:{done:!1,value:r.value.cid}}}}static async fromBytes(t){let{version:r,roots:n,iterator:o}=await pn(t);return new ee(r,n,o)}static async fromIterable(t){let{version:r,roots:n,iterator:o}=await yn(t);return new ee(r,n,o)}};async function pn(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return mn(K(e))}async function yn(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return mn(ye(e))}async function mn(e){let t=pe(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}var kt=Me(Ke(),1);function At(e){let t=Ge({version:1,roots:e}),r=kt.default.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function wn(e){return{async setRoots(t){let r=At(t);await e.write(r)},async writeBlock(t){let{cid:r,bytes:n}=t;await e.write(new Uint8Array(kt.default.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},async close(){await e.end()}}}function et(){}function gn(){let e=[],t=null,r=et,n=!1,o=null,i=et,a=()=>(t||(t=new Promise(h=>{r=()=>{t=null,r=et,h()}})),t),c={write(h){e.push(h);let y=a();return i(),y},async end(){n=!0;let h=a();i(),await h}},f={async next(){let h=e.shift();return h?(e.length===0&&r(),{done:!1,value:h}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise(y=>{i=()=>(o=null,i=et,y(f.next()))})),o)}};return{writer:c,iterator:f}}var te=class{constructor(t,r){this._encoder=r,this._mutex=r.setRoots(t),this._ended=!1}async put(t){if(!(t.bytes instanceof Uint8Array)||!t.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=p.asCID(t.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:t.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}static create(t){t=li(t);let{encoder:r,iterator:n}=bn(),o=new te(t,r),i=new tt(n);return{writer:o,out:i}}static createAppender(){let{encoder:t,iterator:r}=bn();t.setRoots=()=>Promise.resolve();let n=new te([],t),o=new tt(r);return{writer:n,out:o}}static async updateRootsInBytes(t,r){let n=K(t);await Ye(n);let o=At(r);if(Number(n.pos)!==o.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${o.length} bytes)`);return t.set(o,0),t}},tt=class{constructor(t){this._iterator=t}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function bn(){let e=gn(),{writer:t,iterator:r}=e;return{encoder:wn(t),iterator:r}}function li(e){if(e===void 0)return[];if(!Array.isArray(e)){let r=p.asCID(e);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let t=[];for(let r of e){let n=p.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(n)}return t}var _t=Me(xn(),1);var we=class{constructor(t,r,n,o,i){this._version=t,this._path=r,this._roots=n,this._index=o,this._order=i,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(t){return this._index.has(t.toString())}async get(t){let r=this._index.get(t.toString());if(!r)return;this._fd||(this._fd=await _t.default.promises.open(this._path,"r"));let n={cid:t,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return W.readRaw(this._fd,n)}async*blocks(){for(let t of this._order){let r=await this.get(p.parse(t));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let t of this._order)yield p.parse(t)}async close(){if(this._fd)return this._fd.close()}static async fromFile(t){if(typeof t!="string")throw new TypeError("fromFile() requires a file path string");let r=await Y.fromIterable((void 0).from(_t.default.createReadStream(t))),n=new Map,o=[];for await(let{cid:i,blockLength:a,blockOffset:c}of r){let f=i.toString();n.set(f,{blockLength:a,blockOffset:c}),o.push(f)}return new we(r.version,t,await r.getRoots(),n,o)}};var Nt={};Rt(Nt,{addBlock:()=>An,addRoot:()=>kn,blockLength:()=>yi,calculateHeaderLength:()=>It,close:()=>_n,createWriter:()=>bi,estimateHeaderLength:()=>gi,headerLength:()=>Ct,resizeHeader:()=>Bt});var Ie=Me(Ke(),1);var hi=wt(),pi={float64:!1,quickEncodeToken:Pe};function Tt(e,t=hi,r=pi){if(Array.isArray(e)){let n=0;for(let o of e)n+=Tt(o,t,r);return n}else{let n=t[e.type.major];if(n.encodedSize===void 0||typeof n.encodedSize!="function")throw new Error(`Encoder for ${e.type.name} does not have an encodedSize()`);return n.encodedSize(e,r)}}var St=class{constructor(t,r){this.bytes=t,this.byteOffset=r,this.roots=[],this.headerSize=r}addRoot(t,r){return kn(this,t,r),this}write(t){return An(this,t),this}close(t){return _n(this,t)}},kn=(e,t,r={})=>{let{resize:n=!1}=r,{bytes:o,headerSize:i,byteOffset:a,roots:c}=e;e.roots.push(t);let f=Ct(e);if(f>i)if(f-i+a<o.byteLength)if(n)Bt(e,f);else throw c.pop(),new RangeError(`Header of size ${i} has no capacity for new root ${t}.
|
|
3
|
+
However there is a space in the buffer and you could call addRoot(root, { resize: root }) to resize header to make a space for this root.`);else throw c.pop(),new RangeError(`Buffer has no capacity for a new root ${t}`)},yi=({cid:e,bytes:t})=>{let r=e.bytes.byteLength+t.byteLength;return Ie.default.encodingLength(r)+r},An=(e,{cid:t,bytes:r})=>{let n=t.bytes.byteLength+r.byteLength,o=Ie.default.encode(n);if(e.byteOffset+o.length+n>e.bytes.byteLength)throw new RangeError("Buffer has no capacity for this block");Ut(e,o),Ut(e,t.bytes),Ut(e,r)},_n=(e,t={})=>{let{resize:r=!1}=t,{roots:n,bytes:o,byteOffset:i,headerSize:a}=e,c=Ge({version:1,roots:n}),f=Ie.default.encode(c.length),h=f.length+c.byteLength;if(a-h===0)return En(e,f,c),o.subarray(0,i);if(r)return Bt(e,h),En(e,f,c),o.subarray(0,e.byteOffset);throw new RangeError(`Header size was overestimated.
|
|
4
|
+
You can use close({ resize: true }) to resize header`)},Bt=(e,t)=>{let{bytes:r,headerSize:n}=e;r.set(r.subarray(n,e.byteOffset),t),e.byteOffset+=t-n,e.headerSize=t},Ut=(e,t)=>{e.bytes.set(t,e.byteOffset),e.byteOffset+=t.length},En=({bytes:e},t,r)=>{e.set(t),e.set(r,t.length)},mi=[new u(s.map,2),new u(s.string,"version"),new u(s.uint,1),new u(s.string,"roots")],wi=new u(s.tag,42),It=e=>{let t=[...mi];t.push(new u(s.array,e.length));for(let n of e)t.push(wi),t.push(new u(s.bytes,{length:n+1}));let r=Tt(t);return Ie.default.encodingLength(r)+r},Ct=({roots:e})=>It(e.map(t=>t.bytes.byteLength)),gi=(e,t=36)=>It(new Array(e).fill(t)),bi=(e,t={})=>{let{roots:r=[],byteOffset:n=0,byteLength:o=e.byteLength,headerSize:i=Ct({roots:r})}=t,a=new Uint8Array(e,n,o),c=new St(a,i);for(let f of r)c.addRoot(f);return c};return Nn(xi);})();
|
|
5
5
|
return IpldCar}));
|
package/dist/src/api.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { CID } from 'multiformats/cid';
|
|
2
|
+
/**
|
|
3
|
+
* Literally any `Iterable` (async or regular).
|
|
4
|
+
*/
|
|
5
|
+
export type AwaitIterable<T> = Iterable<T> | AsyncIterable<T>;
|
|
2
6
|
export type { CID };
|
|
3
7
|
export interface Block {
|
|
4
8
|
cid: CID;
|
|
@@ -17,6 +21,10 @@ export interface RootsReader {
|
|
|
17
21
|
version: number;
|
|
18
22
|
getRoots: () => Promise<CID[]>;
|
|
19
23
|
}
|
|
24
|
+
export interface RootsBufferReader {
|
|
25
|
+
version: number;
|
|
26
|
+
getRoots: () => CID[];
|
|
27
|
+
}
|
|
20
28
|
export interface BlockIterator extends AsyncIterable<Block> {
|
|
21
29
|
}
|
|
22
30
|
export interface CIDIterator extends AsyncIterable<CID> {
|
|
@@ -27,6 +35,12 @@ export interface BlockReader {
|
|
|
27
35
|
blocks: () => BlockIterator;
|
|
28
36
|
cids: () => CIDIterator;
|
|
29
37
|
}
|
|
38
|
+
export interface BlockBufferReader {
|
|
39
|
+
has: (key: CID) => boolean;
|
|
40
|
+
get: (key: CID) => Block | undefined;
|
|
41
|
+
blocks: () => Iterable<Block>;
|
|
42
|
+
cids: () => Iterable<CID>;
|
|
43
|
+
}
|
|
30
44
|
export interface BlockWriter {
|
|
31
45
|
put: (block: Block) => Promise<void>;
|
|
32
46
|
close: () => Promise<void>;
|
|
@@ -52,4 +66,6 @@ export interface WriterChannel {
|
|
|
52
66
|
}
|
|
53
67
|
export interface CarReader extends BlockReader, RootsReader {
|
|
54
68
|
}
|
|
69
|
+
export interface CarBufferReader extends BlockBufferReader, RootsBufferReader {
|
|
70
|
+
}
|
|
55
71
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/src/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,YAAY,EAAE,GAAG,EAAE,CAAA;AAGnB,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,KAAK,CAAC;CAAG;AAE9D,MAAM,WAAW,WAAY,SAAQ,aAAa,CAAC,GAAG,CAAC;CAAG;AAE1D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACnC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;IAC7C,MAAM,EAAE,MAAM,aAAa,CAAA;IAC3B,IAAI,EAAE,MAAM,WAAW,CAAA;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,eAAe,CAAA;IACvE,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,eAAe,CAAA;IACxC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,UAAU,CAAA;CACtD;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,WAAW,CAAA;IACnB,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,SAAU,SAAQ,WAAW,EAAE,WAAW;CAAG"}
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;AAE7D,YAAY,EAAE,GAAG,EAAE,CAAA;AAGnB,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,KAAK,CAAC;CAAG;AAE9D,MAAM,WAAW,WAAY,SAAQ,aAAa,CAAC,GAAG,CAAC;CAAG;AAE1D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACnC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;IAC7C,MAAM,EAAE,MAAM,aAAa,CAAA;IAC3B,IAAI,EAAE,MAAM,WAAW,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAA;IAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,KAAK,GAAG,SAAS,CAAA;IACpC,MAAM,EAAE,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC7B,IAAI,EAAE,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAA;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,eAAe,CAAA;IACvE,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,eAAe,CAAA;IACxC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,UAAU,CAAA;CACtD;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,WAAW,CAAA;IACnB,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,SAAU,SAAQ,WAAW,EAAE,WAAW;CAAG;AAC9D,MAAM,WAAW,eAAgB,SAAQ,iBAAiB,EAAE,iBAAiB;CAAG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./api').Block} Block
|
|
3
|
+
* @typedef {import('./api').BlockHeader} BlockHeader
|
|
4
|
+
* @typedef {import('./api').BlockIndex} BlockIndex
|
|
5
|
+
* @typedef {import('./coding').BytesBufferReader} BytesBufferReader
|
|
6
|
+
* @typedef {import('./coding').CarHeader} CarHeader
|
|
7
|
+
* @typedef {import('./coding').CarV2Header} CarV2Header
|
|
8
|
+
* @typedef {import('./coding').CarV2FixedHeader} CarV2FixedHeader
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Reads header data from a `BytesReader`. The header may either be in the form
|
|
12
|
+
* of a `CarHeader` or `CarV2Header` depending on the CAR being read.
|
|
13
|
+
*
|
|
14
|
+
* @name decoder.readHeader(reader)
|
|
15
|
+
* @param {BytesBufferReader} reader
|
|
16
|
+
* @param {number} [strictVersion]
|
|
17
|
+
* @returns {CarHeader | CarV2Header}
|
|
18
|
+
*/
|
|
19
|
+
export function readHeader(reader: BytesBufferReader, strictVersion?: number | undefined): CarHeader | CarV2Header;
|
|
20
|
+
/**
|
|
21
|
+
* Reads the leading data of an individual block from CAR data from a
|
|
22
|
+
* `BytesBufferReader`. Returns a `BlockHeader` object which contains
|
|
23
|
+
* `{ cid, length, blockLength }` which can be used to either index the block
|
|
24
|
+
* or read the block binary data.
|
|
25
|
+
*
|
|
26
|
+
* @name async decoder.readBlockHead(reader)
|
|
27
|
+
* @param {BytesBufferReader} reader
|
|
28
|
+
* @returns {BlockHeader}
|
|
29
|
+
*/
|
|
30
|
+
export function readBlockHead(reader: BytesBufferReader): BlockHeader;
|
|
31
|
+
/**
|
|
32
|
+
* Returns Car header and blocks from a Uint8Array
|
|
33
|
+
*
|
|
34
|
+
* @param {Uint8Array} bytes
|
|
35
|
+
* @returns {{ header : CarHeader | CarV2Header , blocks: Block[]}}
|
|
36
|
+
*/
|
|
37
|
+
export function fromBytes(bytes: Uint8Array): {
|
|
38
|
+
header: CarHeader | CarV2Header;
|
|
39
|
+
blocks: Block[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Creates a `BytesBufferReader` from a `Uint8Array`.
|
|
43
|
+
*
|
|
44
|
+
* @name decoder.bytesReader(bytes)
|
|
45
|
+
* @param {Uint8Array} bytes
|
|
46
|
+
* @returns {BytesBufferReader}
|
|
47
|
+
*/
|
|
48
|
+
export function bytesReader(bytes: Uint8Array): BytesBufferReader;
|
|
49
|
+
/**
|
|
50
|
+
* Wraps a `BytesBufferReader` in a limiting `BytesBufferReader` which limits maximum read
|
|
51
|
+
* to `byteLimit` bytes. It _does not_ update `pos` of the original
|
|
52
|
+
* `BytesBufferReader`.
|
|
53
|
+
*
|
|
54
|
+
* @name decoder.limitReader(reader, byteLimit)
|
|
55
|
+
* @param {BytesBufferReader} reader
|
|
56
|
+
* @param {number} byteLimit
|
|
57
|
+
* @returns {BytesBufferReader}
|
|
58
|
+
*/
|
|
59
|
+
export function limitReader(reader: BytesBufferReader, byteLimit: number): BytesBufferReader;
|
|
60
|
+
export type Block = import('./api').Block;
|
|
61
|
+
export type BlockHeader = import('./api').BlockHeader;
|
|
62
|
+
export type BlockIndex = import('./api').BlockIndex;
|
|
63
|
+
export type BytesBufferReader = import('./coding').BytesBufferReader;
|
|
64
|
+
export type CarHeader = import('./coding').CarHeader;
|
|
65
|
+
export type CarV2Header = import('./coding').CarV2Header;
|
|
66
|
+
export type CarV2FixedHeader = import('./coding').CarV2FixedHeader;
|
|
67
|
+
//# sourceMappingURL=buffer-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-decoder.d.ts","sourceRoot":"","sources":["../../src/buffer-decoder.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,mCAJW,iBAAiB,uCAEf,SAAS,GAAG,WAAW,CA+BnC;AA6BD;;;;;;;;;GASG;AACH,sCAHW,iBAAiB,GACf,WAAW,CAiBvB;AAED;;;;;GAKG;AACH,iCAHW,UAAU;YACG,SAAS,GAAG,WAAW;YAAW,KAAK,EAAE;EAoBhE;AAED;;;;;;GAMG;AACH,mCAHW,UAAU,GACR,iBAAiB,CAmC7B;AAED;;;;;;;;;GASG;AACH,oCAJW,iBAAiB,aACjB,MAAM,GACJ,iBAAiB,CAuC7B;oBA1NY,OAAO,OAAO,EAAE,KAAK;0BACrB,OAAO,OAAO,EAAE,WAAW;yBAC3B,OAAO,OAAO,EAAE,UAAU;gCAC1B,OAAO,UAAU,EAAE,iBAAiB;wBACpC,OAAO,UAAU,EAAE,SAAS;0BAC5B,OAAO,UAAU,EAAE,WAAW;+BAC9B,OAAO,UAAU,EAAE,gBAAgB"}
|