Skip to content

compress.bzip2 #

compress.bzip2

Pure V bzip2 encoder/decoder.

Features

  • Pure V implementation (no C wrappers)
  • bzip2 stream compression (BZh1..BZh9)
  • bzip2 stream decompression
  • Block and stream CRC validation
  • Deterministic output for identical input/params

API

import compress.bzip2

compressed := bzip2.compress('hello'.bytes())!
plain := bzip2.decompress(compressed)!
assert plain.bytestr() == 'hello'

With params:

import compress.bzip2

data := 'hello'.bytes()
compressed := bzip2.compress(data, block_size: 1)!
plain := bzip2.decompress(compressed, verify_crc: true)!
assert plain.bytestr() == 'hello'

Notes

  • Randomized legacy bzip2 blocks are intentionally rejected.
  • API currently works on full byte slices (no streaming interface yet).

Test

v test vlib/compress/bzip2/

Proof

  • tested against the official bzip2 C library using a variety of inputs and parameters.
  • deterministic and produces identical output for identical input and parameters.
  • includes CRC validation to ensure data integrity during compression and decompression.
  • rejects randomized legacy bzip2 blocks, ensuring only valid bzip2 streams are processed.
  • tested with a variety of inputs, including edge cases, to ensure robustness and reliability.

fn compress #

fn compress(src []u8, params CompressParams) ![]u8

compress compresses src into a bzip2 byte stream.

fn decompress #

fn decompress(src []u8, params DecompressParams) ![]u8

decompress decompresses a bzip2 byte stream.

struct CompressParams #

@[params]
struct CompressParams {
pub:
	block_size int = 9 // Valid range is 1..9 (100k to 900k block size).
}

vfmt on

struct DecompressParams #

@[params]
struct DecompressParams {
pub:
	verify_crc bool = true
}