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

Method constructor

cbor/text_encoder_stream.ts:45–66  ·  view source on GitHub ↗

* Constructs a new instance.

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

numberToArrayFunction · 0.90
toByteStreamFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected