From c62794269165275361c1475ff803fc24784836a4 Mon Sep 17 00:00:00 2001 From: "chris.lu@gmail.com" Date: Mon, 30 Jul 2012 08:52:11 +0000 Subject: [PATCH] adding uncompressing support! git-svn-id: https://weed-fs.googlecode.com/svn/trunk@61 282b0af5-e82d-9cf1-ede4-77906d7719d0 --- weed-fs/src/cmd/weedvolume/weedvolume.go | 6 +++++- weed-fs/src/pkg/storage/compress.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/weed-fs/src/cmd/weedvolume/weedvolume.go b/weed-fs/src/cmd/weedvolume/weedvolume.go index 1bd790946..e2ebfc53f 100644 --- a/weed-fs/src/cmd/weedvolume/weedvolume.go +++ b/weed-fs/src/cmd/weedvolume/weedvolume.go @@ -65,7 +65,11 @@ func GetHandler(w http.ResponseWriter, r *http.Request) { mtype := mime.TypeByExtension(ext) w.Header().Set("Content-Type", mtype) if storage.IsCompressable(ext, mtype){ - w.Header().Set("Content-Encoding", "gzip") + if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip"){ + w.Header().Set("Content-Encoding", "gzip") + }else{ + n.Data = storage.UnGzipData(n.Data) + } } } w.Write(n.Data) diff --git a/weed-fs/src/pkg/storage/compress.go b/weed-fs/src/pkg/storage/compress.go index 9e63a9fe8..74088a3c4 100644 --- a/weed-fs/src/pkg/storage/compress.go +++ b/weed-fs/src/pkg/storage/compress.go @@ -4,6 +4,7 @@ import ( "bytes" "compress/flate" "compress/gzip" + "io/ioutil" "log" "strings" ) @@ -34,3 +35,13 @@ func GzipData(input []byte) []byte { } 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 { + log.Printf("error uncompressing data:%s\n", err) + } + return output +}