diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-11-11 22:34:40 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-11-11 22:34:40 +0300 |
| commit | 5ac2d4821f56531adb126159aafc36963deb13b3 (patch) | |
| tree | 35dd14018d953d19326eee9a45933e3699a7b9af | |
| parent | fix ReadBitsToSlice logic v2 (diff) | |
| download | bitreader-5ac2d4821f56531adb126159aafc36963deb13b3.tar.gz bitreader-5ac2d4821f56531adb126159aafc36963deb13b3.tar.bz2 bitreader-5ac2d4821f56531adb126159aafc36963deb13b3.zip | |
fix ReadBitsToSlice logic v3v1.2.7
| -rw-r--r-- | bitreader.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/bitreader.go b/bitreader.go index e455d5d..2ea4d05 100644 --- a/bitreader.go +++ b/bitreader.go | |||
| @@ -162,18 +162,21 @@ func (reader *ReaderType) TryReadBitsToSlice(bits int) []byte { | |||
| 162 | out := make([]byte, bytes) | 162 | out := make([]byte, bytes) |
| 163 | for i := 0; i < bytes; i++ { | 163 | for i := 0; i < bytes; i++ { |
| 164 | if i == bytes-1 { // Not enough to fill a whole byte | 164 | if i == bytes-1 { // Not enough to fill a whole byte |
| 165 | val, err := reader.ReadBits(bits % 8) | 165 | if bits%8 != 0 { |
| 166 | val, err := reader.ReadBits(bits % 8) | ||
| 167 | if err != nil { | ||
| 168 | panic(err) | ||
| 169 | } | ||
| 170 | out[i] = byte(val) | ||
| 171 | } | ||
| 172 | break | ||
| 173 | } else { | ||
| 174 | val, err := reader.ReadBytes(1) | ||
| 166 | if err != nil { | 175 | if err != nil { |
| 167 | panic(err) | 176 | panic(err) |
| 168 | } | 177 | } |
| 169 | out[i] = byte(val) | 178 | out[i] = byte(val) |
| 170 | break | ||
| 171 | } | ||
| 172 | val, err := reader.ReadBytes(1) | ||
| 173 | if err != nil { | ||
| 174 | panic(err) | ||
| 175 | } | 179 | } |
| 176 | out[i] = byte(val) | ||
| 177 | } | 180 | } |
| 178 | return out | 181 | return out |
| 179 | } | 182 | } |