aboutsummaryrefslogtreecommitdiff
path: root/weed/operation/compress.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-04-06 14:14:28 -0700
committerChris Lu <chris.lu@gmail.com>2019-04-06 14:14:28 -0700
commit174bf1e8b2ecfc23e375dcbbf3fca28d73ed172f (patch)
treed6e334200860b4c2b61640731a0eed0e22bff69e /weed/operation/compress.go
parent02191f6156d2f2087a1a37465ec7c9937ca4fff2 (diff)
downloadseaweedfs-174bf1e8b2ecfc23e375dcbbf3fca28d73ed172f.tar.xz
seaweedfs-174bf1e8b2ecfc23e375dcbbf3fca28d73ed172f.zip
more efficient client side gzip compression
Diffstat (limited to 'weed/operation/compress.go')
-rw-r--r--weed/operation/compress.go37
1 files changed, 25 insertions, 12 deletions
diff --git a/weed/operation/compress.go b/weed/operation/compress.go
index fedc877dd..a28fb33ec 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) {
+
// text
if strings.HasPrefix(mtype, "text/") {
- return true
+ return true, true
}
// images
switch ext {
case ".svg", ".bmp":
- return true
+ return true, true
}
if strings.HasPrefix(mtype, "image/") {
- return false
+ return false, true
}
// by file name extension
switch ext {
case ".zip", ".rar", ".gz", ".bz2", ".xz":
- return false
+ return false, true
case ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json":
- return true
+ return true, true
case ".php", ".java", ".go", ".rb", ".c", ".cpp", ".h", ".hpp":
- return true
+ return true, true
case ".png", ".jpg", ".jpeg":
- return false
+ return false, true
}
// by mime type
if 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) {