Buffer (@std/buffer)
@std/buffer wraps Zeus’s native u8[] with a Buffer type offering encodings and fixed-width
integer accessors, a subset of Node’s Buffer.
import { Buffer, fromString, alloc } from "@std/buffer";
let b: Buffer = fromString("hello");console.log(b.toHex()); // 68656c6c6fconsole.log(b.toBase64()); // aGVsbG8=Constructing
new Buffer(data: u8[])alloc(size: i32): Buffer // `size` zero bytesfromString(s: string): Buffer // UTF-8 bytes of sfromHex(s: string): BufferfromBase64(s: string): Bufferconcat(a: Buffer, b: Buffer): BufferInstance methods
b.length(): i32b.get(index: i32): u8b.set(index: i32, value: u8): voidb.bytes(): u8[] // underlying array (not a copy)b.toString(): string // decode as UTF-8b.toHex(): stringb.toBase64(): stringb.slice(start: i32, end: i32): Bufferb.equals(other: Buffer): boolean
b.readUInt8(offset): i32 b.writeUInt8(value, offset)b.readUInt16LE(offset): i32 b.writeUInt16LE(value, offset)b.readUInt32LE(offset): i64 b.writeUInt32LE(value, offset)