sqliteHeader(): Coder<SqliteHeader>
Creates a coder for the 100-byte SQLite database file header.
Nothing is validated on encode or decode — magic and every reserved or
fixed-value field (maxEmbeddedPayloadFraction,
minEmbeddedPayloadFraction, leafPayloadFraction,
reservedForExpansion) are written and read exactly as given.
This coder only describes the fixed header. Page 1's B-tree page header follows immediately at byte offset 100 and is out of scope here.
Decode a known header from raw bytes
Decode a known header from raw bytes
import { assertEquals } from "@std/assert"; import { sqliteHeader, SQLITE_HEADER_SIZE, SQLITE_MAGIC, SQLITE_TEXT_ENCODING, } from "@binstruct/sqlite"; // deno-fmt-ignore const wire = new Uint8Array([ 0x53, 0x51, 0x4c, 0x69, 0x74, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x33, 0x00, 0x10, 0x00, 0x01, 0x01, 0x00, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x76, 0x88, 0x00, 0x2e, 0x76, 0x88, ]); const [decoded, read] = sqliteHeader().decode(wire); assertEquals(read, SQLITE_HEADER_SIZE); assertEquals(decoded.magic, SQLITE_MAGIC); assertEquals(decoded.pageSize, 4096); assertEquals(decoded.textEncoding, SQLITE_TEXT_ENCODING.UTF8); assertEquals(decoded.sqliteVersionNumber, 3045000);
Coder<SqliteHeader>
A coder for SqliteHeader values.