aboutsummaryrefslogtreecommitdiff
path: root/weed
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-06-24 11:39:09 -0700
committerChris Lu <chris.lu@gmail.com>2020-06-24 11:39:12 -0700
commit5be12eea37b8a4b6d330e8bfb1d0fa9b17158d06 (patch)
tree2d3a4ec6a6d42f8b94ef571f8be160c1b0281840 /weed
parent2ff37ccdbd3b8d26d84d61881967846833757aab (diff)
downloadseaweedfs-5be12eea37b8a4b6d330e8bfb1d0fa9b17158d06.tar.xz
seaweedfs-5be12eea37b8a4b6d330e8bfb1d0fa9b17158d06.zip
zstd fix
Diffstat (limited to 'weed')
-rw-r--r--weed/util/compression.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/weed/util/compression.go b/weed/util/compression.go
index de6bf0800..b526f47c9 100644
--- a/weed/util/compression.go
+++ b/weed/util/compression.go
@@ -25,6 +25,13 @@ func GzipData(input []byte) ([]byte, error) {
}
return buf.Bytes(), nil
}
+
+var zstdEncoder, _ = zstd.NewWriter(nil)
+
+func ZstdData(input []byte) ([]byte, error) {
+ return zstdEncoder.EncodeAll(input, nil), nil
+}
+
func DecompressData(input []byte) ([]byte, error) {
if IsGzippedContent(input) {
return ungzipData(input)
@@ -46,10 +53,9 @@ func ungzipData(input []byte) ([]byte, error) {
return output, err
}
-var zstdEncoder, _ = zstd.NewWriter(nil)
-
+var decoder, _ = zstd.NewReader(nil)
func unzstdData(input []byte) ([]byte, error) {
- return zstdEncoder.EncodeAll(input, nil), nil
+ return decoder.DecodeAll(input, nil)
}
func IsGzippedContent(data []byte) bool {
@@ -63,7 +69,7 @@ func IsZstdContent(data []byte) bool {
if len(data) < 4 {
return false
}
- return data[0] == 0xFD && data[1] == 0x2F && data[2] == 0xB5 && data[3] == 0x28
+ return data[3] == 0xFD && data[2] == 0x2F && data[1] == 0xB5 && data[0] == 0x28
}
/*