f794ed48c0
If caller wrote a divisible by eight number of bits it would write an extra byte. Also increment by to_write instead of BUF_BYTES which overly pads the bitstream.