// A Writer writes bits to the underlying writer, but only when a "chunk" is
// filled. To write a partial chunk (for example, half of a bit), the write
// must be committed.
A Writer writes bits to the underlying writer, but only when a "chunk" is
filled. To write a partial chunk (for example, half of a bit), the write
must be committed.
// A Writer writes bits to the underlying writer but only when a " chunk " is // filled . To write a partial chunk ( for example half of a bit ) the write // must be committed .
func ExampleWriter() {
	var buff bytes.Buffer
	w := bitio.NewWriter(&buff, 2)
	written, _ := w.WriteBits(0xFFF, 12)
	fmt.Printf("%d bits written\n", written)
	written, _ = w.CommitPending()
	fmt.Printf("%d bits written\n", written)
	for i, b := range buff.Bytes() {
		fmt.Printf("byte %d = 0x%02X\n", i, b)
	}
}
func ExampleWriter ( ) { var buff bytes . Buffer w := bitio . NewWriter ( & buff , 2 ) written , _ := w . WriteBits ( 0xFFF , 12 ) fmt . Printf ( " \n " , written ) written , _ = w . CommitPending ( ) fmt . Printf ( " \n " , written ) for i , b := range buff . Bytes ( ) { fmt . Printf ( " \n " , i , b ) } }
A Writer writes bits to the underlying writer, but only when a "chunk" is
filled.
A Writer writes bits to the underlying writer but only when a " chunk " is filled .
// A writer with a chunk size of 2 bytes. // 12 1 bits written. A chunk requires 16 bits (2 bytes), so the write is currently // pending. // Now we commit the pending bits. // Output: // 0 bits written // 16 bits written // byte 0 = 0xFF // byte 1 = 0xF0