interface TextDecoder { decode(input?: any): string; } interface TextEncoder { encode(input?: string): Uint8Array; } /** * Tiny buffer class for UTF8 strings. * @internal * * It is a subclass of Uint8Array with the added capacity to encode/decode text from/into string and therefore requires to be initialised with BS.setupEncodeDecoder() as such: * * ```javascript * // Encode & Decode using Buffer class (nodejs) * BS.setupEncodeDecoder( * { * encode(s) { * return BS.create(Buffer.from(s || '')) * }, * }, * { * decode(bs) { * return Buffer.from(bs).toString() * }, * } * ) * ``` * * or * * ```javascript * // Encode & Decode using TextEncoder and TextDecoder class (nodejs) * // import { TextEncoder, TextDecoder } from 'util' // required in nodejs * BS.setupEncodeDecoder(new TextEncoder(), new TextDecoder()) * ``` * * @remarks * * Use `BS.create()` to create an instance. * `slice()` and `subarray()` will return a BS instance. * */ export declare class BS extends Uint8Array { /** * Test whether this byte string is the start of another one for a given length * * const abc = BS.create('abc') * const abcdef = BS.create('abcdef') * abc.isStartOf(abcdef, 3) === true * abc.isStartOf(abcdef, 4) === false */ isStartOf(bs: Uint8Array, length: number): boolean; /** * Test strick equality * * const abc1 = BS.create('abc') * const abc2 = BS.create('abc') * abc1 !== abc2 * abc1.equals(abc2) === true */ equals(bs: Uint8Array): boolean; /** creates an istance from a string or a Uint8Array */ static create: (input: string | Uint8Array) => BS; /** * Extend a byte string with another one * * const abc = BS.create('abc') * const def = BS.create('def') * const abcdef = abc.append(def) * abcdef.toString() === 'abcdef' */ append(tail: BS): BS; /** converts to string */ toString(start?: number, length?: number): string; /** @internal */ static encode(_input?: string): BS; /** @internal */ static decode(_input?: BS): string; /** Defines encoder and decoder - must be called before use */ static setupEncodeDecoder(textEncoder: TextEncoder, textDecoder: TextDecoder): void; /** @internal peeks the first few chars for debugging */ get _(): string; /** @internal singleton reffering to an empty array (used for initialisation of internal variables) */ static get EMPTY(): BS; } /** @internal */ export interface BS { slice(start?: number, end?: number): BS; subarray(start?: number, end?: number): BS; } export {};