MCPcopy Create free account
hub / github.com/denoland/std / constructor

Method constructor

cbor/byte_encoder_stream.ts:46–68  ·  view source on GitHub ↗

* Constructs a new instance.

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

numberToArrayFunction · 0.90
toByteStreamFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected