Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
614 B

package bytecounter
import (
"io"
"sync/atomic"
)
// Reader allows to count read bytes.
type Reader struct {
r io.Reader
count uint64
}
// NewReader allocates a Reader.
func NewReader(r io.Reader) *Reader {
return &Reader{
r: r,
}
}
// Read implements io.Reader.
func (r *Reader) Read(p []byte) (int, error) {
n, err := r.r.Read(p)
atomic.AddUint64(&r.count, uint64(n))
return n, err
}
// Count returns received bytes.
func (r *Reader) Count() uint64 {
return atomic.LoadUint64(&r.count)
}
// SetCount sets read bytes.
func (r *Reader) SetCount(v uint64) {
atomic.StoreUint64(&r.count, v)
}