mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:00:54 +00:00
Merge pull request #1498 from JessonChan/develop
compress level test fixed
This commit is contained in:
commit
a71c4283e8
@ -18,6 +18,7 @@ import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -31,9 +32,13 @@ type acceptEncoder struct {
|
||||
}
|
||||
|
||||
var (
|
||||
noneCompressEncoder = acceptEncoder{"", func(wr io.Writer, level int) (io.Writer, error) { return wr, nil }}
|
||||
gzipCompressEncoder = acceptEncoder{"gzip", func(wr io.Writer, level int) (io.Writer, error) { return gzip.NewWriterLevel(wr, level) }}
|
||||
deflateCompressEncoder = acceptEncoder{"deflate", func(wr io.Writer, level int) (io.Writer, error) { return flate.NewWriter(wr, level) }}
|
||||
noneCompressEncoder = acceptEncoder{"", func(wr io.Writer, level int) (io.Writer, error) { return wr, nil }}
|
||||
gzipCompressEncoder = acceptEncoder{"gzip", func(wr io.Writer, level int) (io.Writer, error) { return gzip.NewWriterLevel(wr, level) }}
|
||||
//according to the sec :http://tools.ietf.org/html/rfc2616#section-3.5 ,the deflate compress in http is zlib indeed
|
||||
//deflate
|
||||
//The "zlib" format defined in RFC 1950 [31] in combination with
|
||||
//the "deflate" compression mechanism described in RFC 1951 [29].
|
||||
deflateCompressEncoder = acceptEncoder{"deflate", func(wr io.Writer, level int) (io.Writer, error) { return zlib.NewWriterLevel(wr, level) }}
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -2,8 +2,8 @@ package beego
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -43,7 +43,7 @@ func TestOpenStaticFileGzip_1(t *testing.T) {
|
||||
func TestOpenStaticFileDeflate_1(t *testing.T) {
|
||||
file, _ := os.Open(licenseFile)
|
||||
var zipBuf bytes.Buffer
|
||||
fileWriter, _ := flate.NewWriter(&zipBuf, flate.BestCompression)
|
||||
fileWriter, _ := zlib.NewWriterLevel(&zipBuf, zlib.BestCompression)
|
||||
io.Copy(fileWriter, file)
|
||||
fileWriter.Close()
|
||||
content, _ := ioutil.ReadAll(&zipBuf)
|
||||
|
Loading…
Reference in New Issue
Block a user