mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
sampling whether the data can be gzipped
This commit is contained in:
parent
5463560912
commit
2286eda575
|
@ -78,9 +78,13 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
|
||||||
contentIsGzipped := isInputGzipped
|
contentIsGzipped := isInputGzipped
|
||||||
shouldGzipNow := false
|
shouldGzipNow := false
|
||||||
if !isInputGzipped {
|
if !isInputGzipped {
|
||||||
if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); mtype == "" || iAmSure && shouldBeZipped {
|
if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); iAmSure && shouldBeZipped {
|
||||||
shouldGzipNow = true
|
shouldGzipNow = true
|
||||||
contentIsGzipped = true
|
contentIsGzipped = true
|
||||||
|
} else if len(data) > 128 {
|
||||||
|
var compressed []byte
|
||||||
|
compressed, err = util.GzipData(data[0:128])
|
||||||
|
shouldGzipNow = len(compressed)*10 < 128*9 // can not compress to less than 90%
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +94,12 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
|
||||||
// this could be double copying
|
// this could be double copying
|
||||||
clearDataLen = len(data)
|
clearDataLen = len(data)
|
||||||
if shouldGzipNow {
|
if shouldGzipNow {
|
||||||
data, err = util.GzipData(data)
|
compressed, compressErr := util.GzipData(data)
|
||||||
|
// fmt.Printf("data is compressed from %d ==> %d\n", len(data), len(compressed))
|
||||||
|
if compressErr == nil {
|
||||||
|
data = compressed
|
||||||
|
contentIsGzipped = true
|
||||||
|
}
|
||||||
} else if isInputGzipped {
|
} else if isInputGzipped {
|
||||||
// just to get the clear data length
|
// just to get the clear data length
|
||||||
clearData, err := util.UnGzipData(data)
|
clearData, err := util.UnGzipData(data)
|
||||||
|
|
Loading…
Reference in a new issue