Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirmwareInstall method could wrap io.Reader for file length #268

Open
joelrebel opened this issue Apr 25, 2022 · 0 comments
Open

FirmwareInstall method could wrap io.Reader for file length #268

joelrebel opened this issue Apr 25, 2022 · 0 comments

Comments

@joelrebel
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant