mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-12 01:35:02 +00:00
31 lines
463 B
Go
31 lines
463 B
Go
|
package bytecounter
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
// Writer allows to count written bytes.
|
||
|
type Writer struct {
|
||
|
w io.Writer
|
||
|
count uint32
|
||
|
}
|
||
|
|
||
|
// NewWriter allocates a Writer.
|
||
|
func NewWriter(w io.Writer) *Writer {
|
||
|
return &Writer{
|
||
|
w: w,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Write implements io.Writer.
|
||
|
func (w *Writer) Write(p []byte) (int, error) {
|
||
|
n, err := w.w.Write(p)
|
||
|
w.count += uint32(n)
|
||
|
return n, err
|
||
|
}
|
||
|
|
||
|
// Count returns written bytes.
|
||
|
func (w Writer) Count() uint32 {
|
||
|
return w.count
|
||
|
}
|