golang / cwg

Community outreach Working Group
132 stars 21 forks source link

binary.Read accepting os.File as first parameter as replacement for reader #39

Closed xinkiknix closed 6 years ago

xinkiknix commented 6 years ago

In following code: func ReadFile(filename string) (JPGFile, error) { jpgFile := JPGFile{} in, err := os.Open(filename) defer in.Close() if err != nil { return jpgFile, err } binary.Read(in, binary.LittleEndian, &jpgFile) return jpgFile, nil }

binary.Read accepts "in" (os.File) as a reader, but if I pass the file as a parameter to the function I get the correct error message that "in" is not a reader as defined in the documentation: func Read(r io.Reader, order ByteOrder, data interface{}) error

davecheney commented 6 years ago

We don't the issue tracker to ask questions. Please see https://golang.org/wiki/Questions for good places to ask. Thanks.