Browse Source

Revert "add error return for (Un)GzipData"

This reverts commit 8243710351.
pull/2/head
Chris Lu 12 years ago
parent
commit
a502b78c3f
  1. 4
      weed-fs/src/cmd/weed/volume.go
  2. 38
      weed-fs/src/pkg/storage/compress.go
  3. 4
      weed-fs/src/pkg/storage/needle.go

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

@ -156,9 +156,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
} else { } else {
if n.Data, err = storage.UnGzipData(n.Data); err != nil {
debug("lookup error:", err, r.URL.Path)
}
n.Data = storage.UnGzipData(n.Data)
} }
} }
} }

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

@ -15,35 +15,49 @@ func IsGzippable(ext, mtype string) bool {
if strings.HasPrefix(mtype, "text/"){ if strings.HasPrefix(mtype, "text/"){
return true return true
} }
switch ext {
case ".zip", ".rar", ".gz", ".bz2", ".xz":
if ext == ".zip" {
return false return false
case ".pdf", ".txt", ".html", ".css", ".js", ".json":
}
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 return true
} }
if strings.HasPrefix(mtype, "application/") { if strings.HasPrefix(mtype, "application/") {
if strings.HasSuffix(mtype, "xml") ||
strings.HasSuffix(mtype, "script") {
if strings.HasSuffix(mtype, "xml") {
return true
}
if strings.HasSuffix(mtype, "script") {
return true return true
} }
} }
return false return false
} }
func GzipData(input []byte) ([]byte, error) {
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)
return nil, 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 nil, err
} }
return buf.Bytes(), nil
return buf.Bytes()
} }
func UnGzipData(input []byte) ([]byte, error) {
func UnGzipData(input []byte) []byte {
buf := bytes.NewBuffer(input) buf := bytes.NewBuffer(input)
r, _ := gzip.NewReader(buf) r, _ := gzip.NewReader(buf)
defer r.Close() defer r.Close()
@ -51,5 +65,5 @@ func UnGzipData(input []byte) ([]byte, error) {
if err != nil { if err != nil {
println("error uncompressing data:", err) println("error uncompressing data:", err)
} }
return output, err
return output
} }

4
weed-fs/src/pkg/storage/needle.go

@ -64,9 +64,7 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) {
mtype = contentType mtype = contentType
} }
if IsGzippable(ext, mtype) { if IsGzippable(ext, mtype) {
if data, e = GzipData(data); e != nil {
return
}
data = GzipData(data)
n.SetGzipped() n.SetGzipped()
} }
if ext == ".gz" { if ext == ".gz" {

Loading…
Cancel
Save