// NewDecoder() creates a new decoder to read from a bit stream. func NewDecoder(r *bitio.Reader) (*Decoder, error) { var d uint64 for i := uint8(1); i <= moffetB; i++ { b, err := r.ReadBit() if err != nil { return nil, err } d = (d << 1) + uint64(b) } return &Decoder{r, d, halfInterval}, nil }
// readBits() creates a bit channel from a bitio.Reader(). func readBits(in *bitio.Reader, bits chan<- byte) { count := 0 for { b, err := in.ReadBit() count++ if err != nil { log.Printf("Stopping after %v bits", count) close(bits) return } bits <- b } }