Skip to content

A library for handling bit-level IO to and from files. Currently, this is in a prototypical stage, so changes are inevitable.

Notifications You must be signed in to change notification settings

cartoush/bit_buffers

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bit_buffers

The bit_buffers library allows for the reading and writing of individual bits to and from bit buffers.

doc tests integration tests

This library offers prototype versions of a bit reading entity and a bit writing entity that both keep track of how many bits are contained within them, and at which bit they are currently using.

Example Usage (writing bits to a file)

If you want to save a sequence of bits to a file, use a BitWriter.

// main.rs
use bit_buffers::BitWriter;

fn main() {

    // Create the writer
    let mut bit_writer = BitWriter::new();

    // Write out the desired bits
    bit_writer.write_bit(1);
    bit_writer.write_bit(0);
    bit_writer.write_bit(1);
    bit_writer.write_bit(1);
    bit_writer.write_bit(1);
    bit_writer.write_bit(1);
    bit_writer.write_bit(0);
    bit_writer.write_bit(1);
}

Future Goals

- Thread Safety

As of now, this library has not been tested in a multi-threaded application. Neither BitReader nor BitWriter are guaranteed to be thread safe at this time.

- Sharability

When reading and writing bits from and to files, the user's system determines the endianness. This may lead to problems when trying to share bit files across a network. A future goal is to standardize how the number of bits are written to and read from such files.

- Optimization

When bits are written to a BitWriter, they are written directly to an internal vector of bytes. The code as of now is messy and error-prone. Adding an additional buffer may simplify the underlying logic.

Additionally, for every 8 bits of data written, a re-allocation may need to take place. Adding features to allow users to reserve an expected amount of space may amortize the cost of reading and writing bits over time.

- Additional Features

Currently, there is no way for a user to index into the buffer to read specific bits or overwrite bits.

About

A library for handling bit-level IO to and from files. Currently, this is in a prototypical stage, so changes are inevitable.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%