2024-05-17 18:30:33 +08:00
|
|
|
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
|
2022-02-15 14:55:49 +08:00
|
|
|
|
|
|
|
|
package writers
|
|
|
|
|
|
|
|
|
|
import "io"
|
|
|
|
|
|
|
|
|
|
type BytesCounterWriter struct {
|
|
|
|
|
writer io.Writer
|
|
|
|
|
count int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewBytesCounterWriter(rawWriter io.Writer) *BytesCounterWriter {
|
|
|
|
|
return &BytesCounterWriter{writer: rawWriter}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 19:45:57 +08:00
|
|
|
func (this *BytesCounterWriter) RawWriter() io.Writer {
|
|
|
|
|
return this.writer
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-15 14:55:49 +08:00
|
|
|
func (this *BytesCounterWriter) Write(p []byte) (n int, err error) {
|
|
|
|
|
n, err = this.writer.Write(p)
|
|
|
|
|
this.count += int64(n)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *BytesCounterWriter) Close() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *BytesCounterWriter) TotalBytes() int64 {
|
|
|
|
|
return this.count
|
|
|
|
|
}
|