-
Notifications
You must be signed in to change notification settings - Fork 1
/
raw.go
53 lines (42 loc) · 791 Bytes
/
raw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package rvz
import (
"errors"
"io"
)
type rawReader struct {
i, g int
r *reader
gr io.ReadCloser
offset int64
}
func (rr *rawReader) Read(p []byte) (n int, err error) {
if rr.offset == int64(rr.r.raw[rr.i].RawDataOff+rr.r.raw[rr.i].RawDataSize) {
return n, io.EOF
}
if rr.gr == nil {
if rr.gr, _, err = rr.r.groupReader(rr.g, rr.offset, false); err != nil {
return
}
}
n, err = rr.gr.Read(p)
rr.offset += int64(n)
if err != nil {
if !errors.Is(err, io.EOF) {
return
}
if err = rr.gr.Close(); err != nil {
return
}
rr.g++
rr.gr, err = nil, nil
}
return
}
func newRawReader(r *reader, i int) io.Reader {
return &rawReader{
i: i,
g: int(r.raw[i].GroupIndex),
r: r,
offset: int64(r.raw[i].RawDataOff),
}
}