Files
rclone/cmd/archive/files/countwriter.go
Fawzib Rojas cc09978b79
Some checks failed
build / windows (push) Has been cancelled
build / other_os (push) Has been cancelled
build / mac_amd64 (push) Has been cancelled
build / mac_arm64 (push) Has been cancelled
build / linux (push) Has been cancelled
build / go1.24 (push) Has been cancelled
build / linux_386 (push) Has been cancelled
build / lint (push) Has been cancelled
build / android-all (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/386 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/amd64 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v6 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v7 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm64 (push) Has been cancelled
Build & Push Docker Images / Merge & Push Final Docker Image (push) Has been cancelled
Added rclone archive command to create and read archive files
Co-Authored-By: Nick Craig-Wood <nick@craig-wood.com>
2025-10-30 16:20:48 +00:00

35 lines
666 B
Go

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()
}