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