FirmwareInstall method could wrap io.Reader for file length
joelrebel opened this issue · 0 comments
joelrebel commented
If length is required, maybe consider a different interface like fs.File
or you could declare an interface like
type LengthReader interface {
io.Reader
Len() int
}
which is satisfied by bytes.Buffer
and strings.Reader
and provide a helper for os.File/fs.File
like
type lr struct {
fs.File
}
func (lr *r) Len() int {
info, err := r.Stat()
if err != nil {
panic(err) // or ignore/log
}
return int(info.Size())
}
// LengthReaderFromFile returns a LengthReader from an fs.File
func LengthReaderFromFile(f fs.File) LengthReader {
return &lr{f}
}
Originally posted by @micahhausler in #261 (comment)