1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-23 11:14:48 +02:00
imgproxy/transport/fs/file_limiter.go
2022-09-07 18:03:12 +06:00

28 lines
352 B
Go

package fs
import (
"io"
"net/http"
)
type fileLimiter struct {
f http.File
left int
}
func (lr *fileLimiter) Read(p []byte) (n int, err error) {
if lr.left <= 0 {
return 0, io.EOF
}
if len(p) > lr.left {
p = p[0:lr.left]
}
n, err = lr.f.Read(p)
lr.left -= n
return
}
func (lr *fileLimiter) Close() error {
return lr.f.Close()
}