Skip to content

Commit a22ae8a

Browse files
committed
Add BinaryReader2.ReadAt
1 parent 3087cda commit a22ae8a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

binary.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,16 @@ func (r *BinaryReader2) Read(b []byte) (int, error) {
574574
return n, err
575575
}
576576

577+
// ReadAt complies with io.ReaderAt.
578+
func (r *BinaryReader2) ReadAt(b []byte, off int64) (int, error) {
579+
data, err := r.f.Bytes(len(b), off)
580+
if err != nil && err != io.EOF {
581+
return 0, err
582+
}
583+
n := copy(b, data)
584+
return n, err
585+
}
586+
577587
// ReadBytes reads n bytes.
578588
func (r *BinaryReader2) ReadBytes(n int) []byte {
579589
data, err := r.f.Bytes(n, r.pos)

0 commit comments

Comments
 (0)