lotus/lib/padreader/padreader.go
laser 3623925f66 replace go-bls-sigs and go-sectorbuilder with filecoin-ffi
- remove old submodules and add new submodule
- update build tooling to consume new unified static library
- update consumers of old libs to use new package
2019-11-26 18:16:37 -08:00

39 lines
742 B
Go

package padreader
import (
"io"
"math/bits"
sectorbuilder "github.com/filecoin-project/filecoin-ffi"
)
func PaddedSize(size uint64) uint64 {
logv := 64 - bits.LeadingZeros64(size)
sectSize := uint64(1 << logv)
bound := sectorbuilder.GetMaxUserBytesPerStagedSector(sectSize)
if size <= bound {
return bound
}
return sectorbuilder.GetMaxUserBytesPerStagedSector(1 << (logv + 1))
}
type nullReader struct{}
func (nr nullReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 0
}
return len(b), nil
}
func New(r io.Reader, size uint64) (io.Reader, uint64) {
padSize := PaddedSize(size)
return io.MultiReader(
io.LimitReader(r, int64(size)),
io.LimitReader(nullReader{}, int64(padSize-size)),
), padSize
}