Skip to main content

Crate bblock

Crate bblock 

Source
Expand description

Checksummed persistent blocks built on top of bstack.

§Overview

bblock wraps any BStackAllocator and appends a 4-byte checksum to every allocation. Two checksum strategies are available:

ModuleChecksumUpdate strategyUse when
checksum::crcCRC32Full-block recomputeDetection strength matters most
checksum::xorXORIncremental (changed bytes only)Write throughput matters most

Both modules expose the same API shape. All types are re-exported at checksum (e.g. checksum::BCrcBlock) and at the crate root for backward compatibility.

§Composability

Both allocator wrappers implement bstack::BStackAllocator themselves, so they can be used in any generic context that accepts T: BStackAllocator. This is what allows BCrcBlock and BXorBlock to implement bstack::BStackGuardedSlice without requiring the stricter BStackSliceAllocator bound.

The wrappers can be composed freely:

use bstack::{BStack, LinearBStackAllocator};
use bblock::checksum::{BCrcBlockAllocator, BXorBlockAllocator};

let stack = BStack::open("data.bstk").unwrap();
// XOR checksum over CRC32-checksummed blocks
let alloc = BXorBlockAllocator::new(BCrcBlockAllocator::new(LinearBStackAllocator::new(stack)));

§bstack guarded feature

When bstack is built with the guarded feature (enabled by default in this crate), all four concrete types implement bstack::BStackGuardedSlice: BCrcBlock, BCrcBlockView, BXorBlock, and BXorBlockView. The view types additionally implement bstack::BStackGuardedSliceSubview.

  • as_slice() returns the data region only (the checksum trailer is hidden; for views, only the view’s sub-range is exposed).
  • write() and zero() automatically keep the checksum consistent. BCrcBlock/BCrcBlockView recompute the full CRC32; BXorBlock/BXorBlockView update incrementally.
  • len(), is_empty() (block types) and len(), is_empty(), read(), write(), zero() (view types) are provided by the trait — callers must use bstack::BStackGuardedSlice.

§Detection, not recovery

bblock only detects corruption — it does not repair or revert. A verify() returning false means the data must not be trusted, but the crate provides no mechanism to restore a previous good value.

§Quick start

§CRC32 (default, stronger integrity)

use bstack::{BStack, BStackAllocator, BStackGuardedSlice, LinearBStackAllocator};
use bblock::BCrcBlockAllocator;

let stack = BStack::open("data.bstk").unwrap();
let alloc = BCrcBlockAllocator::new(LinearBStackAllocator::new(stack));

let block = alloc.alloc(16).unwrap();
block.view().write(b"hello, bblock!!!").unwrap();
assert!(block.verify().unwrap());

§XOR (faster writes)

use bstack::{BStack, BStackAllocator, BStackGuardedSlice, LinearBStackAllocator};
use bblock::checksum::BXorBlockAllocator;

let stack = BStack::open("data.bstk").unwrap();
let alloc = BXorBlockAllocator::new(LinearBStackAllocator::new(stack));

let block = alloc.alloc(16).unwrap();
block.view().write(b"hello, bblock!!!").unwrap();
assert!(block.verify().unwrap());

Re-exports§

pub use checksum::crc;
pub use checksum::xor;
pub use checksum::BCrcBlock;
pub use checksum::BCrcBlockAllocator;
pub use checksum::BCrcBlockReader;
pub use checksum::BCrcBlockView;
pub use checksum::BCrcBlockWriter;
pub use checksum::BXorBlock;
pub use checksum::BXorBlockAllocator;
pub use checksum::BXorBlockReader;
pub use checksum::BXorBlockView;
pub use checksum::BXorBlockWriter;
pub use checksum::CHECKSUM_LENGTH;

Modules§

checksum
Checksum algorithms for block integrity verification.
compress
Transparent compression block types.
crypt
Authenticated-encryption block types.

Type Aliases§

BBlockDeprecated
BBlockAllocatorDeprecated
BBlockReaderDeprecated
BBlockViewDeprecated
BBlockWriterDeprecated