4 releases

0.2.0 Apr 2, 2019
0.1.2 Feb 8, 2016
0.1.1 Dec 31, 2015
0.1.0 Dec 28, 2015

#101 in #reader-writer

Download history 48/week @ 2024-08-03 211/week @ 2024-08-10 49/week @ 2024-08-17 119/week @ 2024-08-24 65/week @ 2024-08-31 84/week @ 2024-09-07 144/week @ 2024-09-14 117/week @ 2024-09-21 74/week @ 2024-09-28 148/week @ 2024-10-05 437/week @ 2024-10-12 1137/week @ 2024-10-19 416/week @ 2024-10-26 111/week @ 2024-11-02 481/week @ 2024-11-09 483/week @ 2024-11-16

1,503 downloads per month
Used in 3 crates

MIT license

15KB
312 lines

bitbit

Bit-at-a-time reader/writer types for Rust

Credits and license

Copyright (c) 2015 Robert Norris. MIT license. See LICENSE.


lib.rs:

bitbit provides functions to read and write streams one bit at a time.

Reading

let r = File::open("somefile")?;
let mut br = BitReader::new(r);

let is_one = br.read_bit()?;

let byte = br.read_byte()?;

let num = br.read_bits(5)?;

Using a buffered reader will improve performance:

let r = File::open("somefile")?;
let buff_reader = BufReader::new(r);
let mut br: BitReader<_, MSB> = BitReader::new(buff_reader);

Writing

let w = File::create("somefile")?;
let mut bw = BitWriter::new(w);

bw.write_bit(true)?;

bw.write_byte(0x55)?;

bw.write_bits(0x15, 5)?;

bw.pad_to_byte();

Using a buffered writer will improve performance

let w = File::create("somefile")?;
let mut buf_writer = BufWriter::new(w);
let mut bw = BitWriter::new(&mut buf_writer);
...
buf_writer.flush();

No runtime deps