Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

add error return for (Un)GzipData

Tamás Gulácsi824371035109
diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.go
index 59a5623ea2..576096dbbc 100644
--- a/weed-fs/src/cmd/weed/volume.go
+++ b/weed-fs/src/cmd/weed/volume.go
@@ -42,7 +42,7 @@ var (
store *storage.Store
)
-var fileNameEscaper = strings.NewReplacer("\\","\\\\","\"","\\\"")
+var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
func statusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
@@ -156,7 +156,9 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip")
} else {
- n.Data = storage.UnGzipData(n.Data)
+ if n.Data, err = storage.UnGzipData(n.Data); err != nil {
+ debug("lookup error:", err, r.URL.Path)
+ }
}
}
}
diff --git a/weed-fs/src/pkg/storage/compress.go b/weed-fs/src/pkg/storage/compress.go
index 9df85b4da1..35de706003 100644
--- a/weed-fs/src/pkg/storage/compress.go
+++ b/weed-fs/src/pkg/storage/compress.go
@@ -10,54 +10,40 @@ import (
/*
* Default more not to gzip since gzip can be done on client side.
-*/
+ */
func IsGzippable(ext, mtype string) bool {
- if strings.HasPrefix(mtype, "text/"){
- return true
- }
- if ext == ".zip" {
- return false
- }
- if ext == ".rar" {
- return false
- }
- if ext == ".gz" {
- return false
- }
- if ext == ".pdf" {
+ if strings.HasPrefix(mtype, "text/") {
return true
}
- if ext == ".css" {
- return true
- }
- if ext == ".js" {
+ switch ext {
+ case ".zip", ".rar", ".gz", ".bz2", ".xz":
+ return false
+ case ".pdf", ".txt", ".html", ".css", ".js", ".json":
return true
}
- if ext == ".json" {
- return true
- }
if strings.HasPrefix(mtype, "application/") {
- if strings.HasSuffix(mtype, "xml") {
- return true
- }
- if strings.HasSuffix(mtype, "script") {
+ if strings.HasSuffix(mtype, "xml") ||
+ strings.HasSuffix(mtype, "script") {
return true
}
}
return false
}
-func GzipData(input []byte) []byte {
+
+func GzipData(input []byte) ([]byte, error) {
buf := new(bytes.Buffer)
w, _ := gzip.NewWriterLevel(buf, flate.BestCompression)
if _, err := w.Write(input); err != nil {
println("error compressing data:", err)
+ return nil, err
}
if err := w.Close(); err != nil {
println("error closing compressed data:", err)
+ return nil, err
}
- return buf.Bytes()
+ return buf.Bytes(), nil
}
-func UnGzipData(input []byte) []byte {
+func UnGzipData(input []byte) ([]byte, error) {
buf := bytes.NewBuffer(input)
r, _ := gzip.NewReader(buf)
defer r.Close()
@@ -65,5 +51,5 @@ func UnGzipData(input []byte) []byte {
if err != nil {
println("error uncompressing data:", err)
}
- return output
+ return output, err
}
diff --git a/weed-fs/src/pkg/storage/needle.go b/weed-fs/src/pkg/storage/needle.go
index 867852362b..1f778c7ff2 100644
--- a/weed-fs/src/pkg/storage/needle.go
+++ b/weed-fs/src/pkg/storage/needle.go
@@ -12,8 +12,8 @@ import (
)
const (
- NeedleHeaderSize = 16 //should never change this
- NeedlePaddingSize = 8
+ NeedleHeaderSize = 16 //should never change this
+ NeedlePaddingSize = 8
NeedleChecksumSize = 4
)
@@ -64,7 +64,9 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) {
mtype = contentType
}
if IsGzippable(ext, mtype) {
- data = GzipData(data)
+ if data, e = GzipData(data); e != nil {
+ return
+ }
n.SetGzipped()
}
if ext == ".gz" {