section_writer.go 427 B

1234567891011121314151617181920212223
  1. package missinggo
  2. import "io"
  3. type SectionWriter struct {
  4. w io.WriterAt
  5. off, len int64
  6. }
  7. func NewSectionWriter(w io.WriterAt, off, len int64) *SectionWriter {
  8. return &SectionWriter{w, off, len}
  9. }
  10. func (me *SectionWriter) WriteAt(b []byte, off int64) (n int, err error) {
  11. if off >= me.len {
  12. err = io.EOF
  13. return
  14. }
  15. if off+int64(len(b)) > me.len {
  16. b = b[:me.len-off]
  17. }
  18. return me.w.WriteAt(b, me.off+off)
  19. }