read in case cross chunks

This commit is contained in:
Chris Lu
2020-04-29 02:42:58 -07:00
parent f9da859720
commit 7c10602b49

View File

@@ -98,18 +98,20 @@ func NewChunkStreamReaderFromFiler(masterClient *wdclient.MasterClient, chunks [
} }
} }
func (c *ChunkStreamReader) Read(p []byte) (n int, err error) { func (c *ChunkStreamReader) Read(p []byte) (n int, err error) {
for n < len(p) {
if c.isBufferEmpty() { if c.isBufferEmpty() {
if c.chunkIndex >= len(c.chunkViews) { if c.chunkIndex >= len(c.chunkViews) {
return 0, io.EOF return n, io.EOF
} }
chunkView := c.chunkViews[c.chunkIndex] chunkView := c.chunkViews[c.chunkIndex]
c.fetchChunkToBuffer(chunkView) c.fetchChunkToBuffer(chunkView)
c.chunkIndex++ c.chunkIndex++
} }
n = copy(p, c.buffer[c.bufferPos:]) t := copy(p[n:], c.buffer[c.bufferPos:])
c.bufferPos += n c.bufferPos += t
n += t
}
return return
} }