Skip to content

Commit eb2f01a

Browse files
committed
swarm/storage: Allow EOF at the end of the reader in the chunker. Handle the case when Read returns less than length of target slice
1 parent a45421b commit eb2f01a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎swarm/storage/chunker.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,14 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data io.Reade
178178
// leaf nodes -> content chunks
179179
chunkData := make([]byte, size+8)
180180
binary.LittleEndian.PutUint64(chunkData[0:8], uint64(size))
181-
_, err := data.Read(chunkData[8:])
182-
if err != nil {
183-
errC <- err
184-
return
181+
var readBytes int64
182+
for readBytes < size {
183+
n, err := data.Read(chunkData[8+readBytes:])
184+
readBytes += int64(n)
185+
if err != nil && !(err == io.EOF && readBytes == size) {
186+
errC <- err
187+
return
188+
}
185189
}
186190
select {
187191
case jobC <- &hashJob{key, chunkData, size, parentWg}:
@@ -371,7 +375,6 @@ func (self *LazyChunkReader) join(b []byte, off int64, eoff int64, depth int, tr
371375
defer parentWg.Done()
372376
// return NewDPA(&LocalStore{})
373377

374-
375378
// chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8]))
376379

377380
// find appropriate block level

0 commit comments

Comments
 (0)