diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2021-08-20 04:22:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-20 04:22:41 -0700 |
| commit | 1b1ab331f60c7ee4bb127d237620e0152606187c (patch) | |
| tree | 832fe19713cbff9c0c15479c3e964eb26970d82c /weed/util/compression.go | |
| parent | 05fc7db755c1beeb5188a65c85288a870e34c16e (diff) | |
| parent | 7720533f84cc6589e07247b1391868b7222cc33d (diff) | |
| download | seaweedfs-1b1ab331f60c7ee4bb127d237620e0152606187c.tar.xz seaweedfs-1b1ab331f60c7ee4bb127d237620e0152606187c.zip | |
Merge pull request #2274 from qieqieplus/gzip-pool
Diffstat (limited to 'weed/util/compression.go')
| -rw-r--r-- | weed/util/compression.go | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/weed/util/compression.go b/weed/util/compression.go index 8699a8117..8158b9ba5 100644 --- a/weed/util/compression.go +++ b/weed/util/compression.go @@ -2,10 +2,7 @@ package util import ( "bytes" - "compress/flate" - "compress/gzip" "fmt" - "io/ioutil" "strings" "github.com/chrislusf/seaweedfs/weed/glog" @@ -42,17 +39,21 @@ func MaybeDecompressData(input []byte) []byte { } func GzipData(input []byte) ([]byte, error) { - buf := new(bytes.Buffer) - w, _ := gzip.NewWriterLevel(buf, flate.BestSpeed) - if _, err := w.Write(input); err != nil { - glog.V(2).Infof("error gzip data: %v", err) + w := new(bytes.Buffer) + _, err := GzipStream(w, bytes.NewReader(input)) + if err != nil { return nil, err } - if err := w.Close(); err != nil { - glog.V(2).Infof("error closing gzipped data: %v", err) + return w.Bytes(), nil +} + +func ungzipData(input []byte) ([]byte, error) { + w := new(bytes.Buffer) + _, err := GunzipStream(w, bytes.NewReader(input)) + if err != nil { return nil, err } - return buf.Bytes(), nil + return w.Bytes(), nil } func DecompressData(input []byte) ([]byte, error) { @@ -67,17 +68,6 @@ func DecompressData(input []byte) ([]byte, error) { return input, UnsupportedCompression } -func ungzipData(input []byte) ([]byte, error) { - buf := bytes.NewBuffer(input) - r, _ := gzip.NewReader(buf) - defer r.Close() - output, err := ioutil.ReadAll(r) - if err != nil { - glog.V(2).Infof("error ungzip data: %v", err) - } - return output, err -} - func IsGzippedContent(data []byte) bool { if len(data) < 2 { return false |
