UNPKG

byte-encodings

Version:

Utilities for encoding and decoding common formats like hex, base64, and varint. Ported from Deno's @std/encoding.

103 lines (99 loc) 3.08 kB
import { U as Uint8Array_ } from './_types-UoFpvNJp.cjs'; import { a as Base64Alphabet } from './_common64-Ct2VviPe.cjs'; /** * TransformStream classes to encode and decode to and from base64 data in a streaming manner. * * ```ts * import { assertEquals } from "@std/assert"; * import { encodeBase64 } from "@std/encoding/unstable-base64"; * import { Base64EncoderStream } from "@std/encoding/unstable-base64-stream"; * import { toText } from "@std/streams"; * * const readable = (await Deno.open("./deno.lock")) * .readable * .pipeThrough(new Base64EncoderStream({ output: "string" })); * * assertEquals( * await toText(readable), * encodeBase64(await Deno.readFile("./deno.lock"), { alphabet: "base64" }), * ); * ``` * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @module */ /** * Transforms a {@linkcode Uint8Array<ArrayBuffer>} stream into a base64 stream. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @typeParam T The type of the base64 stream. * * @example Basic Usage * ```ts * import { assertEquals } from "@std/assert"; * import { encodeBase64 } from "@std/encoding/unstable-base64"; * import { Base64EncoderStream } from "@std/encoding/unstable-base64-stream"; * import { toText } from "@std/streams"; * * const readable = (await Deno.open("./deno.lock")) * .readable * .pipeThrough(new Base64EncoderStream({ output: "string" })); * * assertEquals( * await toText(readable), * encodeBase64(await Deno.readFile("./deno.lock")), * ); * ``` */ declare class Base64EncoderStream<T extends "string" | "bytes"> extends TransformStream<Uint8Array_, T extends "bytes" ? Uint8Array_ : string> { /** * Constructs a new instance. * * @param options The options for the base64 stream. */ constructor(options?: { alphabet?: Base64Alphabet; output?: T; }); } /** * Transforms a base64 stream into a {@link Uint8Array<ArrayBuffer>} stream. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @typeParam T The type of the base64 stream. * * @example Basic Usage * ```ts * import { assertEquals } from "@std/assert"; * import { * Base64DecoderStream, * Base64EncoderStream, * } from "@std/encoding/unstable-base64-stream"; * import { toBytes } from "@std/streams/unstable-to-bytes"; * * const readable = (await Deno.open("./deno.lock")) * .readable * .pipeThrough(new Base64EncoderStream({ output: "string" })) * .pipeThrough(new Base64DecoderStream({ input: "string" })); * * assertEquals( * await toBytes(readable), * await Deno.readFile("./deno.lock"), * ); * ``` */ declare class Base64DecoderStream<T extends "string" | "bytes"> extends TransformStream<T extends "bytes" ? Uint8Array_ : string, Uint8Array_> { /** * Constructs a new instance. * * @param options The options for the base64 stream. */ constructor(options?: { alphabet?: Base64Alphabet; input?: T; }); } export { Base64DecoderStream, Base64EncoderStream, Uint8Array_ };