Browse Source

Default more not to gzip since gzip can be done on client side.

pull/2/head
Chris Lu 12 years ago
parent
commit
264678c9b1
  1. 30
      weed-fs/src/pkg/storage/compress.go

30
weed-fs/src/pkg/storage/compress.go

@ -8,7 +8,13 @@ import (
"strings" "strings"
) )
/*
* Default more not to gzip since gzip can be done on client side.
*/
func IsGzippable(ext, mtype string) bool { func IsGzippable(ext, mtype string) bool {
if strings.HasPrefix(mtype, "text/"){
return true
}
if ext == ".zip" { if ext == ".zip" {
return false return false
} }
@ -18,21 +24,35 @@ func IsGzippable(ext, mtype string) bool {
if ext == ".gz" { if ext == ".gz" {
return false return false
} }
if strings.Index(mtype,"text/")==0 {
if ext == ".pdf" {
return true
}
if ext == ".css" {
return true
}
if ext == ".js" {
return true return true
} }
if strings.Index(mtype,"application/")==0 {
if ext == ".json" {
return true return true
}
if strings.HasPrefix(mtype, "application/") {
if strings.HasSuffix(mtype, "xml") {
return true
}
if strings.HasSuffix(mtype, "script") {
return true
}
} }
return false return false
} }
func GzipData(input []byte) []byte { func GzipData(input []byte) []byte {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
w, _ := gzip.NewWriterLevel(buf, flate.BestCompression) w, _ := gzip.NewWriterLevel(buf, flate.BestCompression)
if _, err := w.Write(input); err!=nil {
if _, err := w.Write(input); err != nil {
println("error compressing data:", err) println("error compressing data:", err)
} }
if err := w.Close(); err!=nil {
if err := w.Close(); err != nil {
println("error closing compressed data:", err) println("error closing compressed data:", err)
} }
return buf.Bytes() return buf.Bytes()
@ -42,7 +62,7 @@ func UnGzipData(input []byte) []byte {
r, _ := gzip.NewReader(buf) r, _ := gzip.NewReader(buf)
defer r.Close() defer r.Close()
output, err := ioutil.ReadAll(r) output, err := ioutil.ReadAll(r)
if err!=nil {
if err != nil {
println("error uncompressing data:", err) println("error uncompressing data:", err)
} }
return output return output

Loading…
Cancel
Save