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

#89 in #reader-writer

Download history 41/week @ 2024-03-24 95/week @ 2024-03-31 53/week @ 2024-04-07 58/week @ 2024-04-14 80/week @ 2024-04-21 85/week @ 2024-04-28 113/week @ 2024-05-05 144/week @ 2024-05-12 103/week @ 2024-05-19 63/week @ 2024-05-26 141/week @ 2024-06-02 249/week @ 2024-06-09 297/week @ 2024-06-16 235/week @ 2024-06-23 49/week @ 2024-06-30 73/week @ 2024-07-07

676 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