-
Notifications
You must be signed in to change notification settings - Fork 3
/
lrs.go
42 lines (37 loc) · 905 Bytes
/
lrs.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
package ebml
import (
"fmt"
"io"
"log"
)
type limitedReadSeeker struct {
*io.LimitedReader
}
func newLimitedReadSeeker(rs io.ReadSeeker, limit int64) *limitedReadSeeker {
return &limitedReadSeeker{&io.LimitedReader{rs, limit}}
}
func (lrs *limitedReadSeeker) String() string {
return fmt.Sprintf("%+v", lrs.LimitedReader)
}
func (lrs *limitedReadSeeker) Seek(offset int64, whence int) (ret int64, err error) {
// log.Println("seek0", lrs, offset, whence)
s := lrs.LimitedReader.R.(io.Seeker)
prevN := lrs.LimitedReader.N
var curr int64
curr, err = s.Seek(0, 1)
if err != nil {
log.Panic(err)
}
ret, err = s.Seek(offset, whence)
if err != nil {
log.Panic(err)
}
lrs.LimitedReader.N += curr - ret
if offset == 0 && whence == 1 {
if lrs.LimitedReader.N != prevN {
log.Panic(lrs.LimitedReader.N, prevN, curr, ret)
}
}
// log.Println("seek1", lrs, offset, whence)
return
}