Class CborTextEncoderStream
Implements
- TransformStream<string, Uint8Array>
Index
Constructors
constructor
- new
Cbor (): CborTextEncoderStreamText Encoder Stream Constructs a new instance.
Returns CborTextEncoderStream
Accessors
readable
- get readable(): ReadableStream<Uint8Array>
The ReadableStream
associated with the instance, which provides the encoded CBOR data as Uint8Array chunks. Returns ReadableStream<Uint8Array>
A ReadableStream
. Example: Usage
import { assert, assertEquals } from "@std/assert";
import {
CborSequenceDecoderStream,
CborTextDecodedStream,
CborTextEncoderStream,
} from "@std/cbor";
const rawMessage = "a".repeat(100);
for await (
const value of ReadableStream.from([rawMessage])
.pipeThrough(new CborTextEncoderStream())
.pipeThrough(new CborSequenceDecoderStream())
) {
assert(typeof value === "string" || value instanceof CborTextDecodedStream);
if (value instanceof CborTextDecodedStream) {
assertEquals((await Array.fromAsync(value)).join(""), rawMessage);
} else assertEquals(value, rawMessage);
}
writable
- get writable(): WritableStream<string>
The WritableStream
associated with the instance, which accepts string chunks to be encoded into CBOR format. Returns WritableStream<string>
A WritableStream
. Example: Usage
import { assert, assertEquals } from "@std/assert";
import {
CborSequenceDecoderStream,
CborTextDecodedStream,
CborTextEncoderStream,
} from "@std/cbor";
const rawMessage = "a".repeat(100);
for await (
const value of ReadableStream.from([rawMessage])
.pipeThrough(new CborTextEncoderStream())
.pipeThrough(new CborSequenceDecoderStream())
) {
assert(typeof value === "string" || value instanceof CborTextDecodedStream);
if (value instanceof CborTextDecodedStream) {
assertEquals((await Array.fromAsync(value)).join(""), rawMessage);
} else assertEquals(value, rawMessage);
}
Methods
Staticfrom
- from(asyncIterable): CborTextEncoderStream
Creates a CborTextEncoderStream instance from an iterable of string chunks.
Parameters
- asyncIterable: AsyncIterable<string, any, any> | Iterable<string, any, any>
The value to encode of type AsyncIterable
or Iterable
Returns CborTextEncoderStream
A CborTextEncoderStream instance of the encoded data.
Example: Usage
import { assert, assertEquals } from "@std/assert";
import {
CborSequenceDecoderStream,
CborTextDecodedStream,
CborTextEncoderStream,
} from "@std/cbor";
const rawMessage = "a".repeat(100);
for await (
const value of CborTextEncoderStream.from([rawMessage])
.readable
.pipeThrough(new CborSequenceDecoderStream())
) {
assert(typeof value === "string" || value instanceof CborTextDecodedStream);
if (value instanceof CborTextDecodedStream) {
assertEquals((await Array.fromAsync(value)).join(""), rawMessage);
} else assertEquals(value, rawMessage);
}- asyncIterable: AsyncIterable<string, any, any> | Iterable<string, any, any>
A TransformStream that encodes a ReadableStream into
CBOR "Indefinite Length Text String".
RFC 8949 - Concise Binary Object Representation (CBOR)
Notice: Each chunk of the ReadableStream is encoded as
its own "Definite Length Text String" meaning space can be saved if large
chunks are pipped through instead of small chunks.
Example: Usage