mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor
This commit is contained in:
parent
0c0f77e2ae
commit
ecb234f75a
|
@ -89,6 +89,7 @@ func ReadAll(masterClient *wdclient.MasterClient, chunks []*filer_pb.FileChunk)
|
||||||
// ---------------- ChunkStreamReader ----------------------------------
|
// ---------------- ChunkStreamReader ----------------------------------
|
||||||
type ChunkStreamReader struct {
|
type ChunkStreamReader struct {
|
||||||
chunkViews []*ChunkView
|
chunkViews []*ChunkView
|
||||||
|
totalSize int64
|
||||||
logicOffset int64
|
logicOffset int64
|
||||||
buffer []byte
|
buffer []byte
|
||||||
bufferOffset int64
|
bufferOffset int64
|
||||||
|
@ -107,9 +108,15 @@ func NewChunkStreamReaderFromFiler(masterClient *wdclient.MasterClient, chunks [
|
||||||
|
|
||||||
chunkViews := ViewFromChunks(lookupFileIdFn, chunks, 0, math.MaxInt64)
|
chunkViews := ViewFromChunks(lookupFileIdFn, chunks, 0, math.MaxInt64)
|
||||||
|
|
||||||
|
var totalSize int64
|
||||||
|
for _, chunk := range chunkViews {
|
||||||
|
totalSize += int64(chunk.Size)
|
||||||
|
}
|
||||||
|
|
||||||
return &ChunkStreamReader{
|
return &ChunkStreamReader{
|
||||||
chunkViews: chunkViews,
|
chunkViews: chunkViews,
|
||||||
lookupFileId: lookupFileIdFn,
|
lookupFileId: lookupFileIdFn,
|
||||||
|
totalSize: totalSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,9 +126,15 @@ func NewChunkStreamReader(filerClient filer_pb.FilerClient, chunks []*filer_pb.F
|
||||||
|
|
||||||
chunkViews := ViewFromChunks(lookupFileIdFn, chunks, 0, math.MaxInt64)
|
chunkViews := ViewFromChunks(lookupFileIdFn, chunks, 0, math.MaxInt64)
|
||||||
|
|
||||||
|
var totalSize int64
|
||||||
|
for _, chunk := range chunkViews {
|
||||||
|
totalSize += int64(chunk.Size)
|
||||||
|
}
|
||||||
|
|
||||||
return &ChunkStreamReader{
|
return &ChunkStreamReader{
|
||||||
chunkViews: chunkViews,
|
chunkViews: chunkViews,
|
||||||
lookupFileId: lookupFileIdFn,
|
lookupFileId: lookupFileIdFn,
|
||||||
|
totalSize: totalSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,20 +161,15 @@ func (c *ChunkStreamReader) isBufferEmpty() bool {
|
||||||
|
|
||||||
func (c *ChunkStreamReader) Seek(offset int64, whence int) (int64, error) {
|
func (c *ChunkStreamReader) Seek(offset int64, whence int) (int64, error) {
|
||||||
|
|
||||||
var totalSize int64
|
|
||||||
for _, chunk := range c.chunkViews {
|
|
||||||
totalSize += int64(chunk.Size)
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch whence {
|
switch whence {
|
||||||
case io.SeekStart:
|
case io.SeekStart:
|
||||||
case io.SeekCurrent:
|
case io.SeekCurrent:
|
||||||
offset += c.bufferOffset + int64(c.bufferPos)
|
offset += c.bufferOffset + int64(c.bufferPos)
|
||||||
case io.SeekEnd:
|
case io.SeekEnd:
|
||||||
offset = totalSize + offset
|
offset = c.totalSize + offset
|
||||||
}
|
}
|
||||||
if offset > totalSize {
|
if offset > c.totalSize {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue