#binary-file #file-format #binary-format #header-file #file #binary-data #file-writer

snowbinary

A header based system for writing and reading binary files using its own format

3 unstable releases

0.4.0 Mar 27, 2024
0.3.1 Nov 21, 2023
0.3.0 Feb 10, 2023
0.2.0 Dec 10, 2021
0.0.0 Apr 16, 2021

#497 in Filesystem

Download history 5/week @ 2024-09-22 10/week @ 2024-09-29

208 downloads per month

MIT/Apache

27KB
477 lines

SnowBinary

Rust Checks Rust Build and Test Rust Build, Test, and Release Crates.io docs.rs rustc-msrv

A basic header based binary file format, writer and reader.

Basic Example

{
    let info = SnowBinInfo::default();    

    let writer = SnowBinWriter::new(info, PATH as PathBuf)?;
    writer.write("Header", DATA as &[u8])?;
} // File is flushed when writer.close() is called or when writer is dropped.

{
    let reader = SnowBinReader::new()?;
    reader.read("Header")?; // Returns data has Vec<u8>
}

Binary Format (Supported by this version)

Spec 2

  • Default Max Header Size: 8 bytes.

  • Default Max Data Size: u64.

  • Start with an 8 byte header of "SNOW_BIN".

  • Then 8 bytes showing the snow binary version. (Spec Version) (u64)

  • Then 4 bytes showing the max header size in bytes. (At least 8 bytes, max of u32::MAX bytes) (u32)

  • Then 1 byte showing the max data size. (u8::MAX, u16::MAX, u32::MAX, u64::MAX) (u8)

  • Then write data:

    • Header of MAX_HEADER_SIZE. (No conflicting header names. This is not checked by the writer or reader.)
    • Data size of MAX_DATA_SIZE.
    • Data.
    • Repeat until \/.
  • End with a MAX_HEADER_SIZE header of "SNOW_END".

  • 32 byte verification hash. (Using blake3)

Dependencies

~1.5MB
~45K SLoC