mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
adding uncompressing support!
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@61 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
parent
50c3f1d4a7
commit
c627942691
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue