Files
Watcharr/server/util/io.go
T
IRHM 4cc9bd3edb make image module way more robust
- Create a better (more) re-usable flow for downloading images to disk and inserting images into the db
- Validate images properly by reading them fully and using DecodeConfig
- Fix some security issues by re-encoding images
- Always outputs one format `jpeg`, which keeps everything "normalized" and adds compression to images (mainly user uploads which might be big).
2026-07-10 20:30:23 +00:00

19 lines
368 B
Go

package util
import (
"errors"
"io"
)
func LimitedReadAll(r io.Reader, maxSize int64) ([]byte, error) {
// LimitReader: Allow reading one extra byte so our maxSize check later works.
b, err := io.ReadAll(io.LimitReader(r, maxSize+1))
if err != nil {
return b, err
}
if int64(len(b)) > maxSize {
return b, errors.New("file is too big")
}
return b, nil
}