Skip to content

Commit

Permalink
implement io.WriterTo on byteCountReadCloser
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonstreator committed Nov 21, 2023
1 parent dbde390 commit 3c8a653
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hlog/internal/mutil/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type byteCountReadCloser struct {
}

var _ io.ReadCloser = (*byteCountReadCloser)(nil)
var _ io.WriterTo = (*byteCountReadCloser)(nil)

func NewByteCountReadCloser(rc io.ReadCloser) *byteCountReadCloser {
return &byteCountReadCloser{
Expand All @@ -28,6 +29,12 @@ func (b *byteCountReadCloser) Close() error {
return b.rc.Close()
}

func (b *byteCountReadCloser) WriteTo(w io.Writer) (int64, error) {
n, err := io.Copy(w, b.rc)
atomic.AddInt64(&b.read, n)
return n, err
}

func (b *byteCountReadCloser) BytesRead() int64 {
return b.read
}

0 comments on commit 3c8a653

Please sign in to comment.