25 releases (stable)

4.1.0 Jun 9, 2024
4.0.4 Jul 25, 2022
3.0.0 Jun 7, 2022
2.0.3 May 31, 2022
0.1.1 Dec 19, 2018

#357 in Encoding

Download history 13/week @ 2024-08-31 16/week @ 2024-09-07 18/week @ 2024-09-14 49/week @ 2024-09-21 28/week @ 2024-09-28 5/week @ 2024-10-05 16/week @ 2024-10-12 6/week @ 2024-10-19 7/week @ 2024-10-26 27/week @ 2024-11-02 3/week @ 2024-11-09 2/week @ 2024-11-16 15/week @ 2024-11-23 13/week @ 2024-11-30 37/week @ 2024-12-07 22/week @ 2024-12-14

88 downloads per month
Used in 2 crates

MIT license

26KB
560 lines

binary_rw

Crate GitHub Workflow Status Coverage Status

A binary reader/writer for the rust language, with a similar syntax to the C# BinaryWriter and BinaryReader

Examples

Example code for reading

extern crate binary_rw;
use binary_rw::{
    filestream::{Filestream, OpenType},
    BinaryReader
};

fn main() {
  let mut fs = Filestream::new("test.bin", OpenType::Open).expect("Failed to open file"); 
  let mut binary_file = BinaryReader::new(&mut fs);

  let read_value = binary_file.read_f32().expect("Failed to read f32");
  println!("{:?}", read_value);
}

Example code for writing

extern crate binary_rs;
use binary_rs::{
    filestream::{Filestream, OpenType},
    BinaryReader
};

fn main() {
  let mut fs = Filestream::new("test.bin", OpenType::OpenAndCreate).expect("Failed to open file"); 
  let mut binary_file = BinaryWriter::new(&mut fs);
  
  let value: f32 = 30.5;
  binary_file.write_f32(value).expect("Failed to write f32");
}

TODO

Dependencies

~240–690KB
~16K SLoC