skippable will skip n bytes. If the supplied reader supports seeking that is used. tmp is used as a temporary buffer for reading. The supplied slice does not need to be the size of the read.
(tmp []byte, n int, allowEOF bool, id uint8)
| 202 | // tmp is used as a temporary buffer for reading. |
| 203 | // The supplied slice does not need to be the size of the read. |
| 204 | func (r *Reader) skippable(tmp []byte, n int, allowEOF bool, id uint8) (ok bool) { |
| 205 | if id < 0x80 { |
| 206 | r.err = fmt.Errorf("internal error: skippable id < 0x80") |
| 207 | return false |
| 208 | } |
| 209 | if fn := r.skippableCB[id-0x80]; fn != nil { |
| 210 | rd := io.LimitReader(r.r, int64(n)) |
| 211 | r.err = fn(rd) |
| 212 | if r.err != nil { |
| 213 | return false |
| 214 | } |
| 215 | _, r.err = io.CopyBuffer(ioutil.Discard, rd, tmp) |
| 216 | return r.err == nil |
| 217 | } |
| 218 | if rs, ok := r.r.(io.ReadSeeker); ok { |
| 219 | _, err := rs.Seek(int64(n), io.SeekCurrent) |
| 220 | if err == nil { |
| 221 | return true |
| 222 | } |
| 223 | if err == io.ErrUnexpectedEOF || (r.err == io.EOF && !allowEOF) { |
| 224 | r.err = ErrCorrupt |
| 225 | return false |
| 226 | } |
| 227 | } |
| 228 | for n > 0 { |
| 229 | if n < len(tmp) { |
| 230 | tmp = tmp[:n] |
| 231 | } |
| 232 | if _, r.err = io.ReadFull(r.r, tmp); r.err != nil { |
| 233 | if r.err == io.ErrUnexpectedEOF || (r.err == io.EOF && !allowEOF) { |
| 234 | r.err = ErrCorrupt |
| 235 | } |
| 236 | return false |
| 237 | } |
| 238 | n -= len(tmp) |
| 239 | } |
| 240 | return true |
| 241 | } |
| 242 | |
| 243 | // Read satisfies the io.Reader interface. |
| 244 | func (r *Reader) Read(p []byte) (int, error) { |
no test coverage detected