From de730b079da4d9e046c4816a4f74a19c4ddf6712 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 7 Aug 2021 15:41:07 -0700 Subject: [PATCH] ChunkStreamReader implenents io.ReaderAt --- weed/filer/stream.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/weed/filer/stream.go b/weed/filer/stream.go index 2ea8ce493..3859f9a67 100644 --- a/weed/filer/stream.go +++ b/weed/filer/stream.go @@ -99,6 +99,7 @@ type ChunkStreamReader struct { } var _ = io.ReadSeeker(&ChunkStreamReader{}) +var _ = io.ReaderAt(&ChunkStreamReader{}) func doNewChunkStreamReader(lookupFileIdFn wdclient.LookupFileIdFunctionType, chunks []*filer_pb.FileChunk) *ChunkStreamReader { @@ -135,6 +136,14 @@ func NewChunkStreamReader(filerClient filer_pb.FilerClient, chunks []*filer_pb.F return doNewChunkStreamReader(lookupFileIdFn, chunks) } +func (c *ChunkStreamReader) ReadAt(p []byte, off int64) (n int, err error) { + _, err = c.Seek(off, io.SeekStart) + if err != nil { + return + } + return c.Read(p) +} + func (c *ChunkStreamReader) Read(p []byte) (n int, err error) { for n < len(p) { if c.isBufferEmpty() {