ffiwrapper: Fix AddPiece with multireaders
This commit is contained in:
parent
57adda40f9
commit
52782b6def
@ -117,20 +117,30 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector abi.SectorID, existingPie
|
||||
var pieceCids []abi.PieceInfo
|
||||
|
||||
for {
|
||||
n, err := pr.Read(buf[:])
|
||||
var read int
|
||||
for rbuf := buf; len(rbuf) > 0; {
|
||||
n, err := pr.Read(rbuf)
|
||||
if err != nil && err != io.EOF {
|
||||
return abi.PieceInfo{}, xerrors.Errorf("pr read error: %w", err)
|
||||
}
|
||||
|
||||
rbuf = rbuf[n:]
|
||||
read += n
|
||||
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
}
|
||||
if read == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
c, err := sb.pieceCid(buf[:n])
|
||||
c, err := sb.pieceCid(buf[:read])
|
||||
if err != nil {
|
||||
return abi.PieceInfo{}, xerrors.Errorf("pieceCid error: %w", err)
|
||||
}
|
||||
pieceCids = append(pieceCids, abi.PieceInfo{
|
||||
Size: abi.UnpaddedPieceSize(len(buf[:n])).Padded(),
|
||||
Size: abi.UnpaddedPieceSize(len(buf[:read])).Padded(),
|
||||
PieceCID: c,
|
||||
})
|
||||
}
|
||||
|
@ -45,7 +45,10 @@ type seal struct {
|
||||
}
|
||||
|
||||
func data(sn abi.SectorNumber, dlen abi.UnpaddedPieceSize) io.Reader {
|
||||
return io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(dlen))
|
||||
return io.MultiReader(
|
||||
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(123)),
|
||||
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(dlen-123)),
|
||||
)
|
||||
}
|
||||
|
||||
func (s *seal) precommit(t *testing.T, sb *Sealer, id abi.SectorID, done func()) {
|
||||
|
Loading…
Reference in New Issue
Block a user