@@ -30,21 +30,21 @@ type BitReader struct {
3030// NewBitReader returns a BitReader that reads chunkLen bits at a time from in.
3131func NewBitReader (chunkLen uint8 , in io.Reader ) (* BitReader , error ) {
3232 // bufSize % chunkLen == 0 so that we never have to read across the buffer boundary
33- bs := & BitReader {chunkLen : chunkLen , in : in , buf : make ([]byte , BufSize - BufSize % int (chunkLen ))}
33+ br := & BitReader {chunkLen : chunkLen , in : in , buf : make ([]byte , BufSize - BufSize % int (chunkLen ))}
3434 var err error
35- bs .bufN , err = bs . in . Read ( bs .buf )
36- if err != nil {
35+ br .bufN , err = io . ReadFull ( br . in , br .buf )
36+ if err != nil && err != io . ErrUnexpectedEOF {
3737 return nil , err
3838 }
39- return bs , nil
39+ return br , nil
4040}
4141
4242// Read returns the next chunkLen bits from the stream. If there is no more data to read, it returns io.EOF.
4343// For example, if chunkLen is 3 and the next 3 bits are 101, Read returns 5, nil.
4444func (br * BitReader ) Read () (byte , error ) {
4545 if br .byteIdx >= br .bufN { // need to read more
46- n , err := br .in . Read ( br .buf )
47- if err != nil {
46+ n , err := io . ReadFull ( br .in , br .buf )
47+ if err != nil && err != io . ErrUnexpectedEOF {
4848 return 0 , err
4949 }
5050 br .byteIdx = 0
0 commit comments