/
githubmirror
/
rclone
Обзор
Документация
Войти
/
githubmirror
/
rclone
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
cmd/archive/files/countwriter.go
34 строки
666 B
Fawzib Rojas
Added rclone archive command to create and read archive files
30 окт 2025, 19:20
30 окт 2025, 19:20
cc09978
Код
Авторство
О чём код?
package files import ( "io" "sync/atomic" ) // CountWriter counts bytes written through it. // It is safe for concurrent Count/Reset; Write is as safe as the wrapped Writer. type CountWriter struct { w io.Writer count atomic.Uint64 } // NewCountWriter wraps w (use nil if you want to drop data). func NewCountWriter(w io.Writer) *CountWriter { if w == nil { w = io.Discard } return &CountWriter{w: w} } func (cw *CountWriter) Write(p []byte) (int, error) { n, err := cw.w.Write(p) if n > 0 { cw.count.Add(uint64(n)) } return n, err } // Count returns the total bytes written. func (cw *CountWriter) Count() uint64 { return cw.count.Load() }