diff options
| author | Chris Lu <chris.lu@gmail.com> | 2012-12-22 13:15:09 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2012-12-22 13:15:09 -0800 |
| commit | 264678c9b1952bc5a6c0777efc49af85dc295fb4 (patch) | |
| tree | 4e2726c7d381b40eb131f66932e00b55f8369049 /weed-fs/src/pkg | |
| parent | 46b8c4cc98663bfe2923d0b7a4edcb117180a260 (diff) | |
| download | seaweedfs-264678c9b1952bc5a6c0777efc49af85dc295fb4.tar.xz seaweedfs-264678c9b1952bc5a6c0777efc49af85dc295fb4.zip | |
Default more not to gzip since gzip can be done on client side.
Diffstat (limited to 'weed-fs/src/pkg')
| -rw-r--r-- | weed-fs/src/pkg/storage/compress.go | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/weed-fs/src/pkg/storage/compress.go b/weed-fs/src/pkg/storage/compress.go index 419cde8ff..9df85b4da 100644 --- a/weed-fs/src/pkg/storage/compress.go +++ b/weed-fs/src/pkg/storage/compress.go @@ -1,49 +1,69 @@ package storage import ( - "bytes" - "compress/flate" - "compress/gzip" - "io/ioutil" - "strings" + "bytes" + "compress/flate" + "compress/gzip" + "io/ioutil" + "strings" ) +/* +* Default more not to gzip since gzip can be done on client side. +*/ func IsGzippable(ext, mtype string) bool { - if ext == ".zip" { - return false - } - if ext == ".rar" { - return false - } - if ext == ".gz" { - return false - } - if strings.Index(mtype,"text/")==0 { - return true - } - if strings.Index(mtype,"application/")==0 { - return true - } - return false + if strings.HasPrefix(mtype, "text/"){ + return true + } + if ext == ".zip" { + return false + } + if ext == ".rar" { + return false + } + if ext == ".gz" { + return false + } + if ext == ".pdf" { + return true + } + if ext == ".css" { + return true + } + if ext == ".js" { + return true + } + if ext == ".json" { + return true + } + if strings.HasPrefix(mtype, "application/") { + if strings.HasSuffix(mtype, "xml") { + return true + } + if strings.HasSuffix(mtype, "script") { + return true + } + } + return false } func GzipData(input []byte) []byte { - buf := new(bytes.Buffer) - w, _ := gzip.NewWriterLevel(buf, flate.BestCompression) - if _, err := w.Write(input); err!=nil { - println("error compressing data:", err) - } - if err := w.Close(); err!=nil { - println("error closing compressed data:", err) - } - return buf.Bytes() + buf := new(bytes.Buffer) + w, _ := gzip.NewWriterLevel(buf, flate.BestCompression) + if _, err := w.Write(input); err != nil { + println("error compressing data:", err) + } + if err := w.Close(); err != nil { + println("error closing compressed data:", err) + } + return buf.Bytes() } func UnGzipData(input []byte) []byte { - buf := bytes.NewBuffer(input) - r, _ := gzip.NewReader(buf) - defer r.Close() - output, err := ioutil.ReadAll(r) - if err!=nil { - println("error uncompressing data:", err) - } - return output + buf := bytes.NewBuffer(input) + r, _ := gzip.NewReader(buf) + defer r.Close() + output, err := ioutil.ReadAll(r) + if err != nil { + println("error uncompressing data:", err) + } + return output } |
