Core BLIP encoding implementation.
encode(value: u64, buf: []u8) !usize— BLIP encode, immediate mode (0-127) or length-prefixeddecode(buf: []const u8) !DecodeResult— BLIP decode, returns value + bytes consumedisSentinel(buf: []const u8) bool— detect overlong (sentinel) encodingsencodeSentinel(value: u7, buf: []u8) !usize— encode a sentinel valueminBytes(value: u64) usize— minimum LE byte width for a value
LEB128 (unsigned) and SLEB128 (signed) variable-length integer encoding.
encode/decode— unsigned LEB128signedEncode/signedDecode— signed SLEB128
Protobuf varint (LEB128 unsigned + ZigZag for signed).
encode/decode— unsigned (same as LEB128)zigzagEncode/zigzagDecode— ZigZag mapping (signed <-> unsigned)signedEncode/signedDecode— ZigZag + LEB128 compose
ASN.1 BER/DER length encoding (big-endian payload, L <= 126).
encode/decode— short form (<128) or long form (0x80|N + N BE bytes)
PrefixVarint encoding (count leading 1-bits for byte count).
encode/decode— unary prefix in first byte determines total length
SQLite varint encoding (Huffman-inspired thresholds).
encode/decode— 0-240 in 1 byte, then threshold-based tiers up to 9 bytes
Common interface re-exporting all encoding modules.
all_encodings— tuple for comptime iteration over all 6 encodings- Re-exports:
blip,leb128,protobuf,asn1,prefix_varint,sqlite
Direct arithmetic on raw little-endian byte slices.
addLE(a, b, out) !usize— LE addition with carry propagationmulLE(a, b, out) !usize— schoolbook LE multiplicationcompareLE(a, b) Order— LE comparison ignoring trailing zeros
Container type tags and sentinel mapping.
ContainerType— enum(u7): array, dict, utf8, raw, file, map, dirtypeSentinel(ct) [2]u8— convert type to 2-byte sentinelparseType(buf) ?ContainerType— parse sentinel from buffer
Core TLV header read/write and self-referential length solver.
ContainerError— error set for all container operationsContainerView— parsed container header (type, total_length, value_offset, buf)computeTotalLength(v_size) u64— solve total = 2 + blip_size(total) + v_sizewriteHeader(type, total, buf) !usize— write type sentinel + BLIP lengthparseHeader(buf) !ContainerView— parse container header from buffer
UTF8 and RAW leaf container serialization/parsing.
serializeUtf8(alloc, text) ![]u8— serialize UTF-8 string containerserializeRaw(alloc, data) ![]u8— serialize raw binary containerreadUtf8(buf) ![]const u8— zero-copy read of UTF8 containerreadRaw(buf) ![]const u8— zero-copy read of RAW container
ARRAY container with index tables and xxHash64.
serializeArray(alloc, elements) ![]u8— fixpoint iteration, index, xxHash64ArrayReader— zero-copy reader: init, elementCount, elementAt, verifyHash
DICT, FILE, and DIR containers with key ordering and interleaved index.
KeyValue— struct { key, value } (pre-serialized container bytes)serializeDict(alloc, pairs) ![]u8— sorted keys, interleaved index, xxHash64serializeFile(alloc, pairs) ![]u8— FILE variant, validates required keys (path, xh64, bina)serializeDir(alloc, pairs) ![]u8— DIR variant, validates required keys (path, xh64; no bina)DictReader— zero-copy reader: init, pairCount, keyAt, valueAt, findKey, verifyHash (supports DICT, FILE, MAP, DIR)extractKeyBytes(key_container) ![]const u8— extract key value from TLV
High-level BLIP archive API (miniBlar flat archives + full archives with DIR).
FileEntry— struct { path, content, metadata }DirEntry— struct { path, xh64, metadata }ArchiveEntry— union(enum) { file: FileEntry, dir: DirEntry }createArchive(alloc, files) ![]u8— build flat FILE-only BLIP archivecreateFullArchive(alloc, entries) ![]u8— build archive with FILE + DIR entriescomputeMerkleHash(child_hashes) [8]u8— xxHash64 of concatenated child hashesArchiveReader— reader: init, verifyMagic, fileCount, fileAt, findFile, entryCount, entryAt, entryTypeAt, verifyHash
C FFI exports for BLIP encoding and container operations.
blip_encode,blip_decode,blip_is_sentinel,blip_encoded_sizeblip_archive_create,blip_archive_file_count,blip_archive_verify,blip_freeblip_archive_create_full— create archive with FILE + DIR entries and metadatablip_archive_entry_type— return entry type (0x05=FILE, 0x07=DIR)blip_archive_entry_metadata— extract mode, mtime, owner from entry
C header for the BLIP FFI (encoding + containers + full archive API).
CLI entry point calling through C FFI. Supports --about, -h/--help, self-test.
Benchmark suite: throughput, bignum math, random-access jumping.
Fuzz roundtrip tests for all encodings (100K random values each).
Shared utilities for blar and miniblar CLIs.
read_file,write_file— file I/O helpersmkdirp,ensure_parent_dir— recursive directory creationprogress_t,progress_init/update/finish— progress bar for interactive terminalsparse_tar_flags— tar-style flag parsing (cf, tf, xf, Vf, If, pf)default_output_name— generate default output path (.blar)normalize_path— strip leading ./ and / from paths
Full-featured BLIP archive CLI with directory + metadata support (calls through C FFI).
cmd_create— recurse directories, collect metadata (mode, mtime, owner), callblip_archive_create_fullcmd_list— show entries with type prefix (d=dir, -=file)cmd_extract— two-pass: create dirs first, then extract files; restore mode + mtimecmd_verify— verify outer hash + per-entry xh64 + Merkle hashescmd_info— report file count, directory count, sizescmd_cat— print single file content to stdout
Minimal BLIP archive CLI for flat file-only archives (calls through C FFI).
- Same commands as blar: create, list, extract, verify, info, cat
- Rejects directory arguments (use blar for directory support)
- Uses
blip_archive_create(not create_full)
Integration tests for blar CLI (18 tests: directory trees, DIR/FILE entries, metadata, Merkle hash, corruption detection).
Integration tests for miniblar CLI (19 tests: flat archives, binary roundtrip, directory rejection).
Unified container expansion and collapse — all 15 format handlers.
detectCodec(content) ?[]const u8— format detection by magic bytesexpandFile(allocator, content, codec_name) !?ExpandResult— expand a file into container entriescollapseContainer(allocator, codec_name, children) !?[]u8— reconstruct original file from expanded childrenexpandPdf(allocator, content) !?ExpandResult— PDF-specific expansion (FlateDecode + JPEG streams)expandZip(allocator, content) !?ExpandResult— ZIP decompositionexpandSlot(allocator, entry, slot, expand, expand_all_zips)— per-entry expansion (thread-safe)
Streaming (spill-to-disk) archive creation with O(largest_file) memory.
createArchiveStreaming(allocator, entries, comp_id, expand, expand_all_zips) ![]u8— two-pass streaming archive creationExpSlot— per-entry expansion result slot for parallel processingisArchiveExtension(path) bool— check if file has archive extension (ZIP skip logic)
computeArrayLayout(allocator, element_sizes, type_id, options) !ArrayLayout— dry-run ARRAY layout from sizes alone (enables streaming assembly)ArrayLayout— struct with header bytes, index section, total size for streaming
BMP image parser for container expansion (24/32-bit uncompressed).
parseBmp(allocator, data) !ParsedBmp— parse BMP → pixels + header metadataencodeBmp(allocator, pixels, header) ![]u8— reconstruct BMP from pixels + header
TGA image parser for container expansion (24/32-bit uncompressed true-color).
parseTga(allocator, data) !ParsedTga— parse TGA → pixels + headerencodeTga(allocator, pixels, header, footer) ![]u8— reconstruct TGA
TIFF image parser for container expansion (uncompressed 8/16-bit).
parseTiff(allocator, data) !ParsedTiff— parse TIFF → pixels + compact metadata (non-pixel bytes)
GIF image parser with LZW decompression (static GIFs only).
parseGif(allocator, data) !ParsedGif— parse GIF → RGBA pixels + original file- LZW decoder:
LzwDecoder,decodeLzw(allocator, compressed, min_code_size, output_size) ![]u8
tar archive parser for container decomposition.
parseTar(allocator, data) !ParsedTar— parse tar → individual entries with headersencodeTar(allocator, entries, trailer) ![]u8— reconstruct tar from entries
WAV audio parser for FLAC container expansion.
parseWav(allocator, data) !ParsedWav— parse WAV → PCM samples + compact metadata
AIFF audio parser for FLAC container expansion (big-endian PCM).
parseAiff(allocator, data) !ParsedAiff— parse AIFF → LE PCM + metadataparseExtended80(buf) u32— decode 80-bit IEEE 754 sample rate
FLAC encoder/decoder wrapper (uses libFLAC via @cImport).
encodePcmToFlac(allocator, samples, channels, rate, bps, frames) ![]u8— PCM → FLACdecodeFlacToPcm(allocator, flac_data, channels, rate, bps, total) ![]u8— FLAC → PCM
FITS astronomy image parser (8/16-bit integer pixel arrays).
parseFits(allocator, data) !ParsedFits— parse FITS → pixels + header metadata
DICOM medical image parser (uncompressed 8/16-bit).
parseDicom(allocator, data) !ParsedDicom— parse DICOM → pixels + tag metadata
NIfTI neuroimaging parser (3D/4D voxel data).
parseNifti(allocator, data) !ParsedNifti— parse NIfTI → voxels + 348-byte header
Compression stub — same API as compression.zig but returns UnsupportedCompression. Used when enable_compression=false for downstream consumers.
Checksum computation (xxHash64, CRC32, BLAKE3-128).
compute(id, data) [32]u8— compute checksumverify(id, data, expected) bool— verify checksum
Archive encryption (AES-256-GCM, ChaCha20-Poly1305) with Argon2id/PBKDF2 KDF.
ZIP container reader/writer for container expansion.
readEntries(allocator, buf) ![]ZipEntry— parse ZIP central directoryextractEntry(allocator, entry) ![]u8— decompress a ZIP entrycreateZip(allocator, entries) ![]u8— create a ZIP from entries
LZMA2 compression integration (via z7z dependency).
C wiring layer — connects CLI/GUI to Zig core via FFI.
entry_list_t— file/dir collection with metadata_only streaming supportexpand_via_zig()— routes all container expansion through blip_expand_file FFIblar_extract_to_dir()— extraction with Zig collapse bridge for all formatsexpand_containers_pass()— parallel expansion with work-stealing queue
C CLI — blar create/extract/list/verify/info with --streaming flag.
C FFI header — declares all Zig-exported functions for C consumers.
Archive creation benchmarks (small/medium/large, in-memory vs streaming, with/without expansion).