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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
more efficient client side gzip compression
Chris Lu174bf1e8b2ec
diff --git a/weed/operation/compress.go b/weed/operation/compress.goindex fedc877dd8..a28fb33eca 100644--- a/weed/operation/compress.go+++ b/weed/operation/compress.go@@ -16,45 +16,58 @@ import (*/func IsGzippable(ext, mtype string, data []byte) bool {+ shouldBeZipped, iAmSure := IsGzippableFileType(ext, mtype)+ if iAmSure {+ return shouldBeZipped+ }++ isMostlyText := util.IsText(data)++ return isMostlyText+}++/*+* Default more not to gzip since gzip can be done on client side.+ */+func IsGzippableFileType(ext, mtype string) (shouldBeZipped, iAmSure bool) {+// textif strings.HasPrefix(mtype, "text/") {- return true+ return true, true}// imagesswitch ext {case ".svg", ".bmp":- return true+ return true, true}if strings.HasPrefix(mtype, "image/") {- return false+ return false, true}// by file name extensionswitch ext {case ".zip", ".rar", ".gz", ".bz2", ".xz":- return false+ return false, truecase ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json":- return true+ return true, truecase ".php", ".java", ".go", ".rb", ".c", ".cpp", ".h", ".hpp":- return true+ return true, truecase ".png", ".jpg", ".jpeg":- return false+ return false, true}// by mime typeif strings.HasPrefix(mtype, "application/") {if strings.HasSuffix(mtype, "xml") {- return true+ return true, true}if strings.HasSuffix(mtype, "script") {- return true+ return true, true}}- isMostlyText := util.IsText(data)-- return isMostlyText+ return false, false}func GzipData(input []byte) ([]byte, error) {diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.goindex 2276c67b78..6bd2998265 100644--- a/weed/operation/upload_content.go+++ b/weed/operation/upload_content.go@@ -2,6 +2,7 @@ package operationimport ("bytes"+ "compress/gzip""encoding/json""errors""fmt"@@ -39,10 +40,24 @@ var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")// Upload sends a POST request to a volume server to upload the contentfunc Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) {+ contentIsGzipped := isGzipped+ shouldGzipNow := false+ if !isGzipped {+ if shouldBeZipped, iAmSure := IsGzippableFileType(filepath.Base(filename), mtype); iAmSure && shouldBeZipped {+ shouldGzipNow = true+ contentIsGzipped = true+ }+ }return upload_content(uploadUrl, func(w io.Writer) (err error) {- _, err = io.Copy(w, reader)+ if shouldGzipNow {+ gzWriter := gzip.NewWriter(w)+ _, err = io.Copy(gzWriter, reader)+ gzWriter.Close()+ } else {+ _, err = io.Copy(w, reader)+ }return- }, filename, isGzipped, mtype, pairMap, jwt)+ }, filename, contentIsGzipped, mtype, pairMap, jwt)}func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) {body_buf := bytes.NewBufferString("")