实现基础的206 partial content缓存

This commit is contained in:
GoEdgeLab
2022-03-03 19:36:28 +08:00
parent 6984257224
commit 619407f9e4
39 changed files with 1139 additions and 271 deletions

View File

@@ -0,0 +1,28 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package writers
import "io"
type BytesCounterWriter struct {
writer io.Writer
count int64
}
func NewBytesCounterWriter(rawWriter io.Writer) *BytesCounterWriter {
return &BytesCounterWriter{writer: rawWriter}
}
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
}