-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbits.go
46 lines (34 loc) · 855 Bytes
/
bits.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package compressor
import (
"io"
"log"
"github.com/dgryski/go-bitstream"
)
// Helper functions to deal with working with bitstreams
func readBit(r *bitstream.BitReader) (value bool, EOF bool) {
bit, err := r.ReadBit()
if err == io.EOF {
return false, false
}
if err != nil {
log.Fatal("compressor: Problem reading stream", err.Error())
}
return bit == bitstream.One, false
}
func readByte(r *bitstream.BitReader) byte {
b, err := r.ReadByte()
if err != nil {
log.Fatal("compressor: Problem reading stream", err.Error())
}
return b
}
func writeByte(w *bitstream.BitWriter, b byte) {
if err := w.WriteByte(b); err != nil {
log.Fatal("Unable to encode:", err.Error())
}
}
func writeBit(w *bitstream.BitWriter, val bitstream.Bit) {
if err := w.WriteBit(val); err != nil {
log.Fatal("Unable to encode:", err.Error())
}
}