Browse Source

adding uncompressing support!

git-svn-id: https://weed-fs.googlecode.com/svn/trunk@61 282b0af5-e82d-9cf1-ede4-77906d7719d0
pull/2/head
chris.lu@gmail.com 13 years ago
parent
commit
c627942691
  1. 4
      weed-fs/src/cmd/weedvolume/weedvolume.go
  2. 11
      weed-fs/src/pkg/storage/compress.go

4
weed-fs/src/cmd/weedvolume/weedvolume.go

@ -65,7 +65,11 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
mtype := mime.TypeByExtension(ext) mtype := mime.TypeByExtension(ext)
w.Header().Set("Content-Type", mtype) w.Header().Set("Content-Type", mtype)
if storage.IsCompressable(ext, mtype){ if storage.IsCompressable(ext, mtype){
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip"){
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
}else{
n.Data = storage.UnGzipData(n.Data)
}
} }
} }
w.Write(n.Data) w.Write(n.Data)

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

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"compress/flate" "compress/flate"
"compress/gzip" "compress/gzip"
"io/ioutil"
"log" "log"
"strings" "strings"
) )
@ -34,3 +35,13 @@ func GzipData(input []byte) []byte {
} }
return buf.Bytes() 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
}
Loading…
Cancel
Save