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.

adding uncompressing support!

[email protected]c62794269165
diff --git a/weed-fs/src/cmd/weedvolume/weedvolume.go b/weed-fs/src/cmd/weedvolume/weedvolume.go
index 1bd790946c..e2ebfc53f7 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 9e63a9fe83..74088a3c46 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
+}