aboutsummaryrefslogtreecommitdiff
path: root/compress.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-11 19:36:43 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-11 19:36:43 +0200
commit6210374fa8653a2493adcfc6c458e27028a1d319 (patch)
tree91528edeff627bf98937c43102fd429591b37f16 /compress.go
parentcode cleanup (diff)
downloadfasthttp-6210374fa8653a2493adcfc6c458e27028a1d319.tar.gz
fasthttp-6210374fa8653a2493adcfc6c458e27028a1d319.tar.bz2
fasthttp-6210374fa8653a2493adcfc6c458e27028a1d319.zip
Implement io.Writer in ByteBuffer and use it instead of bytes.Buffer in isFileCompressible
Diffstat (limited to 'compress.go')
-rw-r--r--compress.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/compress.go b/compress.go
index d723838..c4c5926 100644
--- a/compress.go
+++ b/compress.go
@@ -1,7 +1,6 @@
package fasthttp
import (
- "bytes"
"fmt"
"io"
"os"
@@ -248,8 +247,8 @@ func isFileCompressible(f *os.File, minCompressRatio float64) bool {
// Try compressing the first 4kb of of the file
// and see if it can be compressed by more than
// the given minCompressRatio.
- var buf bytes.Buffer
- zw := acquireGzipWriter(&buf, CompressDefaultCompression)
+ b := AcquireByteBuffer()
+ zw := acquireGzipWriter(b, CompressDefaultCompression)
lr := &io.LimitedReader{
R: f,
N: 4096,
@@ -262,6 +261,7 @@ func isFileCompressible(f *os.File, minCompressRatio float64) bool {
}
n := 4096 - lr.N
- zn := len(buf.Bytes())
+ zn := len(b.B)
+ ReleaseByteBuffer(b)
return float64(zn) < float64(n)*minCompressRatio
}