CborTextDecodedStream
import { CborTextDecodedStream } from "jsr:@ende/cbor";class
class CborTextDecodedStream extends ReadableStream<string>A ReadableStream that wraps the decoded CBOR "Text String". RFC 8949 - Concise Binary Object Representation (CBOR)
Instances of this class is created from CborSequenceDecoderStream. This class is not designed for you to create instances of it yourself. It is merely a way for you to validate the type being returned.
Example: Usage
import { assert, assertEquals } from "@ende/assert";
import {
CborSequenceDecoderStream,
CborTextDecodedStream,
CborTextEncoderStream,
} from "@ende/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);
}
Constructors
constructor
new CborTextDecodedStream(gen: AsyncGenerator<string>, releaseLock: ReleaseLock)Constructs a new instance.
gen: AsyncGenerator<string>A AsyncGenerator
. releaseLock: ReleaseLockA Function that's called when the stream is finished.