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.

detect more gzippable content

Chris Luc043fd17cb8f
diff --git a/weed/operation/compress.go b/weed/operation/compress.go
index de62e5bf73..50958fd504 100644
--- a/weed/operation/compress.go
+++ b/weed/operation/compress.go
@@ -8,21 +8,41 @@ import (
"strings"
"github.com/chrislusf/seaweedfs/weed/glog"
+ "golang.org/x/tools/godoc/util"
)
/*
* Default more not to gzip since gzip can be done on client side.
*/
-func IsGzippable(ext, mtype string) bool {
+func IsGzippable(ext, mtype string, data []byte) bool {
+
+ // text
if strings.HasPrefix(mtype, "text/") {
return true
}
+
+ // images
+ switch ext {
+ case ".svg", ".bmp":
+ return true
+ }
+ if strings.HasPrefix(mtype, "image/") {
+ return false
+ }
+
+ // by file name extention
switch ext {
case ".zip", ".rar", ".gz", ".bz2", ".xz":
return false
case ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json":
return true
+ case ".php", ".java", ".go", ".rb", ".c", ".cpp", ".h", ".hpp":
+ return true
+ case ".png", ".jpg", ".jpeg", "":
+ return true
}
+
+ // by mime type
if strings.HasPrefix(mtype, "application/") {
if strings.HasSuffix(mtype, "xml") {
return true
@@ -31,7 +51,10 @@ func IsGzippable(ext, mtype string) bool {
return true
}
}
- return false
+
+ isMostlyText := util.IsText(data)
+
+ return isMostlyText
}
func GzipData(input []byte) ([]byte, error) {
diff --git a/weed/storage/needle_parse_multipart.go b/weed/storage/needle_parse_multipart.go
index 2ebf86d96c..e8d57ee38a 100644
--- a/weed/storage/needle_parse_multipart.go
+++ b/weed/storage/needle_parse_multipart.go
@@ -87,7 +87,7 @@ func parseMultipart(r *http.Request) (
originalDataSize = len(unzipped)
}
isGzipped = true
- } else if operation.IsGzippable(ext, mtype) {
+ } else if operation.IsGzippable(ext, mtype, data) {
if data, e = operation.GzipData(data); e != nil {
return
}