github.com/storacha/go-ucanto@v0.7.2/examples/retrieval/server/util.go (about) 1 package main 2 3 import ( 4 "io" 5 "os" 6 ) 7 8 type fileSectionReadCloser struct { 9 file *os.File 10 sectionReader *io.SectionReader 11 } 12 13 func (f *fileSectionReadCloser) Read(p []byte) (int, error) { 14 n, err := f.sectionReader.Read(p) 15 if err == io.EOF { 16 return n, f.Close() 17 } 18 return n, err 19 } 20 21 func (f *fileSectionReadCloser) Close() error { 22 return f.file.Close() 23 } 24 25 func newFileSectionReader(file *os.File, off int, n int) *fileSectionReadCloser { 26 return &fileSectionReadCloser{file, io.NewSectionReader(file, int64(off), int64(n))} 27 }