mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
swarm/storage: Fix prepareChunks in pyramid chunker
We need read in a loop until we receive an EOF or the buffer is full, because not all Reader guarantees that it reads the buffer full in one step
This commit is contained in:
parent
7427eab9c5
commit
05ab6ee523
1 changed files with 15 additions and 5 deletions
|
|
@ -414,14 +414,24 @@ func (self *PyramidChunker) prepareChunks(isAppend bool, chunkLevel [][]*TreeEnt
|
|||
var n int
|
||||
var err error
|
||||
chunkData := make([]byte, self.chunkSize+8)
|
||||
maxBuf := len(chunkData)
|
||||
readBytes := 8
|
||||
if unFinishedChunk != nil {
|
||||
copy(chunkData, unFinishedChunk.SData)
|
||||
n, err = data.Read(chunkData[8+unFinishedChunk.Size:])
|
||||
n += int(unFinishedChunk.Size)
|
||||
unFinishedChunk = nil
|
||||
} else {
|
||||
n, err = data.Read(chunkData[8:])
|
||||
readBytes += int(unFinishedChunk.Size)
|
||||
}
|
||||
for readBytes < maxBuf {
|
||||
n0, err0 := data.Read(chunkData[readBytes:])
|
||||
readBytes += n0
|
||||
n += n0
|
||||
if err0 != nil {
|
||||
if err0 != io.EOF || (n0 == 0 && maxBuf == readBytes) || n == 0 || n0 != 0 {
|
||||
err = err0
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
unFinishedChunk = nil
|
||||
|
||||
totalDataSize += n
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue