github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/ioctx/io.go (about) 1 // ioctx adds context.Context to io APIs. 2 // 3 // TODO: Specify policy for future additions to this package. It may be best to only add analogues 4 // of the stdlib "io" so ioctx.* are easy for readers to understand. New functions and types (other 5 // than conversions to and from stdlib types) should be added elsewhere. 6 package ioctx 7 8 import ( 9 "context" 10 ) 11 12 // Reader is io.Reader with context added. 13 type Reader interface { 14 Read(context.Context, []byte) (n int, err error) 15 } 16 17 // Writer is io.Writer with context added. 18 type Writer interface { 19 Write(context.Context, []byte) (n int, err error) 20 } 21 22 // Closer is io.Closer with context added. 23 type Closer interface { 24 Close(context.Context) error 25 } 26 27 // Seeker is io.Seeker with context added. 28 type Seeker interface { 29 Seek(_ context.Context, offset int64, whence int) (int64, error) 30 } 31 32 // ReadCloser is io.ReadCloser with context added. 33 34 type ReadCloser interface { 35 Reader 36 Closer 37 } 38 39 // ReadSeeker is io.ReadSeeker with context added. 40 type ReadSeeker interface { 41 Reader 42 Seeker 43 } 44 45 // ReaderAt is io.ReaderAt with context added. 46 type ReaderAt interface { 47 ReadAt(_ context.Context, dst []byte, off int64) (n int, err error) 48 } 49 50 // WriterAt is io.WriterAt with context added. 51 type WriterAt interface { 52 WriteAt(_ context.Context, p []byte, off int64) (n int, err error) 53 }