From 367ac5b3365e9e4bdf54f93008fed516c3bd314a Mon Sep 17 00:00:00 2001 From: Ross Light Date: Sun, 17 Jan 2021 12:41:01 -0800 Subject: [PATCH] packfile: use io.ReadSeeker for DeltaReader base --- packfile/delta.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packfile/delta.go b/packfile/delta.go index 64797f4..fd3088e 100644 --- a/packfile/delta.go +++ b/packfile/delta.go @@ -27,7 +27,7 @@ import ( // DeltaReader decompresses a deltified object from a packfile. // See details at https://git-scm.com/docs/pack-format#_deltified_representation type DeltaReader struct { - base io.ReaderAt + base io.ReadSeeker delta ByteReader inited bool @@ -37,7 +37,7 @@ type DeltaReader struct { // NewDeltaReader returns a new DeltaReader that applies the given delta to a // base object. -func NewDeltaReader(base io.ReaderAt, delta ByteReader) *DeltaReader { +func NewDeltaReader(base io.ReadSeeker, delta ByteReader) *DeltaReader { return &DeltaReader{ base: base, delta: delta, @@ -108,7 +108,10 @@ func (d *DeltaReader) readInstruction() error { if err != nil { return fmt.Errorf("apply delta: %w", err) } - d.curr = io.NewSectionReader(d.base, int64(offset), int64(size)) + if _, err := d.base.Seek(int64(offset), io.SeekStart); err != nil { + return fmt.Errorf("apply delta: %w", err) + } + d.curr = d.base d.remaining = size case instruction != 0: // Add new data