diff options
author | Tiago Peczenyj <tpeczenyj@weborama.com> | 2023-11-05 14:46:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-05 14:46:42 +0100 |
commit | 4010b16eef6632331ba564dc76174a3db7ff4903 (patch) | |
tree | f6421eb3d5ac5f93ade2d9f692b9249bf3847da3 /compress.go | |
parent | Allow redirect URI path to not be normalized. (#1638) (diff) | |
download | fasthttp-4010b16eef6632331ba564dc76174a3db7ff4903.tar.gz fasthttp-4010b16eef6632331ba564dc76174a3db7ff4903.tar.bz2 fasthttp-4010b16eef6632331ba564dc76174a3db7ff4903.zip |
Add support to fs.fs on serve static files (#1640)
* substitute *os.File by fs.File
* refactor error handling by using the new recommended form
* finish implementation
* substitute seek(offset,0) by seek(offset, io.SeekStart)
* add unit test
* use io.SeekStart on Seek method
Diffstat (limited to 'compress.go')
-rw-r--r-- | compress.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compress.go b/compress.go index 50d381b..8494d56 100644 --- a/compress.go +++ b/compress.go @@ -4,7 +4,7 @@ import ( "bytes" "fmt" "io" - "os" + "io/fs" "sync" "github.com/klauspost/compress/flate" @@ -421,7 +421,7 @@ func newCompressWriterPoolMap() []*sync.Pool { return m } -func isFileCompressible(f *os.File, minCompressRatio float64) bool { +func isFileCompressible(f fs.File, minCompressRatio float64) bool { // Try compressing the first 4kb of the file // and see if it can be compressed by more than // the given minCompressRatio. @@ -433,7 +433,11 @@ func isFileCompressible(f *os.File, minCompressRatio float64) bool { } _, err := copyZeroAlloc(zw, lr) releaseStacklessGzipWriter(zw, CompressDefaultCompression) - f.Seek(0, 0) //nolint:errcheck + seeker, ok := f.(io.Seeker) + if !ok { + return false + } + seeker.Seek(0, io.SeekStart) //nolint:errcheck if err != nil { return false } |