From 3e7f535beae601d334186f7316af957bc24bd865 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Fri, 11 Nov 2016 16:31:04 +0100 Subject: utils/fs: add ReadAt to memory file and tests. (#122) * memory files now implement io.ReaderAt. * tests now check ReadAt behaviour. --- utils/fs/memory/memory.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'utils/fs/memory') diff --git a/utils/fs/memory/memory.go b/utils/fs/memory/memory.go index 08a9599..ef54c37 100644 --- a/utils/fs/memory/memory.go +++ b/utils/fs/memory/memory.go @@ -189,6 +189,16 @@ func newFile(base, fullpath string, flag int) *file { } func (f *file) Read(b []byte) (int, error) { + n, err := f.ReadAt(b, f.position) + if err != nil { + return 0, err + } + + f.position += int64(n) + return n, err +} + +func (f *file) ReadAt(b []byte, off int64) (int, error) { if f.IsClosed() { return 0, fs.ErrClosed } @@ -197,7 +207,7 @@ func (f *file) Read(b []byte) (int, error) { return 0, errors.New("read not supported") } - n, err := f.content.ReadAt(b, f.position) + n, err := f.content.ReadAt(b, off) f.position += int64(n) return n, err -- cgit