Core buffers
@webbuf/fixedbuf
Fixed-sized buffers optimized with Rust/WASM
Install
npm install @webbuf/fixedbuf Usage
import { FixedBuf } from "@webbuf/fixedbuf";
import { WebBuf } from "@webbuf/webbuf";
// Create fixed-size buffers
const buf32 = FixedBuf.alloc<32>(32); // 32-byte buffer
const buf16 = FixedBuf.alloc<16>(16, 0xff); // 16 bytes filled with 0xff
const random = FixedBuf.fromRandom<32>(32); // 32 random bytes
// Create from encoded strings
const fromHex = FixedBuf.fromHex<4>(4, "deadbeef");
const fromB64 = FixedBuf.fromBase64(16, "SGVsbG8gV29ybGQhISE=");
// Create from WebBuf
const webBuf = WebBuf.alloc(32);
const fixed = FixedBuf.fromBuf<32>(32, webBuf);
// Access underlying buffer
const underlying: WebBuf = fixed.buf;
// Convert to strings
fromHex.toHex(); // "deadbeef"
fromB64.toBase64(); // "SGVsbG8gV29ybGQhISE="
// Clone and reverse
const cloned = fixed.clone();
const reversed = fixed.toReverse(); API reference (1 export)
Classes
FixedBuf
classconstructor<N extends number>(size: N, buf: WebBuf): FixedBuf<N>
static fromBuf<N extends number>(size: N, buf: WebBuf): FixedBuf<N>
static alloc<N extends number>(size: N, fill?: number): FixedBuf<N>
static fromHex<N extends number>(size: N, hex: string): FixedBuf<N>
static fromBase64(size: number, base64: string): FixedBuf<number>
static fromBase32<N extends number>(size: N, str: string, options?: Base32Options): FixedBuf<N>
static fromRandom<N extends number>(size: N): FixedBuf<N>
buf: WebBuf
toHex(): string
toBase64(): string
toBase32(options?: Base32Options): string
clone(): FixedBuf<N>
toReverse(): FixedBuf<N>
wipe(): void