UNPKG

byte-encodings

Version:

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

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