* Constructs a new instance.
()
| 44 | * Constructs a new instance. |
| 45 | */ |
| 46 | constructor() { |
| 47 | const { readable, writable } = new TransformStream< |
| 48 | Uint8Array, |
| 49 | Uint8Array |
| 50 | >(); |
| 51 | this.#readable = toByteStream(ReadableStream.from(async function* () { |
| 52 | yield new Uint8Array([0b010_11111]); |
| 53 | for await (const x of readable) { |
| 54 | if (x.length < 24) yield new Uint8Array([0b010_00000 + x.length]); |
| 55 | else if (x.length < 2 ** 8) { |
| 56 | yield new Uint8Array([0b010_11000, x.length]); |
| 57 | } else if (x.length < 2 ** 16) { |
| 58 | yield new Uint8Array([0b010_11001, ...numberToArray(2, x.length)]); |
| 59 | } else if (x.length < 2 ** 32) { |
| 60 | yield new Uint8Array([0b010_11010, ...numberToArray(4, x.length)]); |
| 61 | } // Can safely assume `x.length < 2 ** 64` as JavaScript doesn't support a `Uint8Array` being that large. |
| 62 | else yield new Uint8Array([0b010_11011, ...numberToArray(8, x.length)]); |
| 63 | yield x; |
| 64 | } |
| 65 | yield new Uint8Array([0b111_11111]); |
| 66 | }())); |
| 67 | this.#writable = writable; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Creates a {@link CborByteEncoderStream} instance from an iterable of |
nothing calls this directly
no test coverage detected