Bitwise IO
The basic workflow for writing bytes to disk is as follows:
- Write bytes to buffer, one byte at a time
- Once the buffer is full, write the entire buffer to disk and clear the buffer (i.e., "flush" the buffer)
- Repeat
Similarly, the basic workflow for reading bytes from disk is as follows:
- Read enough bytes from disk to fill the entire buffer (i.e., "fill" the buffer)
- Read bytes from buffer, one byte at a time, until the buffer is empty
- Repeat
If we have no more data to write into the byte buffer, but the buffer haven't been full: flush the buffer
If we have no more data from file to put in the bit buffer: pad the data in bit buffer with zeros
*