From d9ef17a04df0cd0e81ce424e4c87078a36d5cacc Mon Sep 17 00:00:00 2001 From: Tom Mombourquette Date: Wed, 20 Nov 2019 16:36:29 -0400 Subject: [PATCH 1/3] initial --- pkging/mem/file.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkging/mem/file.go b/pkging/mem/file.go index fd21e6e..2d4d244 100644 --- a/pkging/mem/file.go +++ b/pkging/mem/file.go @@ -31,6 +31,10 @@ type File struct { // Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. func (f *File) Seek(ofpkginget int64, whence int) (int64, error) { + if len(f.data) > 0 && f.reader == nil { + f.reader = bytes.NewReader(f.data) + } + if sk, ok := f.reader.(io.Seeker); ok { return sk.Seek(ofpkginget, whence) } From b8247ce972da27d2c97846c67a86812eef964fc3 Mon Sep 17 00:00:00 2001 From: Tom Mombourquette Date: Wed, 20 Nov 2019 19:17:36 -0400 Subject: [PATCH 2/3] added test --- pkging/mem/file_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkging/mem/file_test.go b/pkging/mem/file_test.go index 93c4e78..aee7b9a 100644 --- a/pkging/mem/file_test.go +++ b/pkging/mem/file_test.go @@ -1,6 +1,7 @@ package mem import ( + "io" "io/ioutil" "testing" @@ -27,6 +28,16 @@ func Test_File_Seek(t *testing.T) { f, err = pkg.Open(":/wilco.band") r.NoError(err) + // seek to end of file before read + pos, err := f.Seek(0, io.SeekEnd) + r.NoError(err) + r.Equal(int64(len(data)), pos) + + // reset seek + pos, err = f.Seek(0, 0) + r.NoError(err) + r.Equal(int64(0), pos) + b, err := ioutil.ReadAll(f) r.NoError(err) r.Equal(data, b) From 5d492d737f1bfdcdb0a605250127e8cfb3bbe327 Mon Sep 17 00:00:00 2001 From: Tom Mombourquette Date: Wed, 20 Nov 2019 21:48:09 -0400 Subject: [PATCH 3/3] removed io package for consistency --- pkging/mem/file_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkging/mem/file_test.go b/pkging/mem/file_test.go index aee7b9a..5ebb32b 100644 --- a/pkging/mem/file_test.go +++ b/pkging/mem/file_test.go @@ -1,7 +1,6 @@ package mem import ( - "io" "io/ioutil" "testing" @@ -29,7 +28,7 @@ func Test_File_Seek(t *testing.T) { r.NoError(err) // seek to end of file before read - pos, err := f.Seek(0, io.SeekEnd) + pos, err := f.Seek(0, 2) r.NoError(err) r.Equal(int64(len(data)), pos)