github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/writers/writer_bytes_counter.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package writers 4 5 import "io" 6 7 type BytesCounterWriter struct { 8 writer io.Writer 9 count int64 10 } 11 12 func NewBytesCounterWriter(rawWriter io.Writer) *BytesCounterWriter { 13 return &BytesCounterWriter{writer: rawWriter} 14 } 15 16 func (this *BytesCounterWriter) RawWriter() io.Writer { 17 return this.writer 18 } 19 20 func (this *BytesCounterWriter) Write(p []byte) (n int, err error) { 21 n, err = this.writer.Write(p) 22 this.count += int64(n) 23 return 24 } 25 26 func (this *BytesCounterWriter) Close() error { 27 return nil 28 } 29 30 func (this *BytesCounterWriter) TotalBytes() int64 { 31 return this.count 32 }