MCPcopy
hub / github.com/klauspost/compress / skippable

Method skippable

s2/reader.go:204–241  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

202// tmp is used as a temporary buffer for reading.
203// The supplied slice does not need to be the size of the read.
204func (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.
244func (r *Reader) Read(p []byte) (int, error) {

Callers 3

ReadMethod · 0.95
DecodeConcurrentMethod · 0.95
SkipMethod · 0.95

Calls 1

SeekMethod · 0.45

Tested by

no test coverage detected