On 22/09/22, 'Dan Kortschak' via golang-nuts (golang-nuts@googlegroups.com) wrote: > On Thu, 2022-09-22 at 00:58 +0100, Rory Campbell-Lange wrote: > > interface conversion: *zip.checksumReader is not io.ReadSeeker: > > missing method Seek > > Would it be acceptable to conditionally copy the reader's contents into > a buffer that implements io.ReadSeeker? > > if rs, ok := r.(io.ReadSeeker); ok { > useReadSeeker(rs) > } else { > b, err := io.ReadAll(r) > // handle err > useReadSeeker(bytes.NewReader(b)) > }
Thanks very much for the suggestion. The following works ok as a test (which is basically your code): fileAsReadSeeker := func(file fs.File) io.ReadSeeker { if rs, ok := file.(io.ReadSeeker); ok { return rs } b, err := io.ReadAll(file) if err != nil { panic(err) // to fix } return bytes.NewReader(b) } I'm now thinking of adding in a bytes.Buffer field into the underlying struct holding the fs.File file which can be initialised (and reused) if an io.ReadSeeker is required and provides a clearer error path. Thanks again, Rory -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/YyyorOZAuyXyIQYx%40campbell-lange.net.