|
|
@ -9,7 +9,7 @@ import ( |
|
|
|
"strings" |
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog" |
|
|
|
"github.com/klauspost/compress/zstd" |
|
|
|
// "github.com/klauspost/compress/zstd"
|
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
@ -55,19 +55,16 @@ 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) |
|
|
|
} |
|
|
|
/* |
|
|
|
if IsZstdContent(input) { |
|
|
|
return unzstdData(input) |
|
|
|
} |
|
|
|
*/ |
|
|
|
return input, UnsupportedCompression |
|
|
|
} |
|
|
|
|
|
|
@ -82,12 +79,6 @@ func ungzipData(input []byte) ([]byte, error) { |
|
|
|
return output, err |
|
|
|
} |
|
|
|
|
|
|
|
var decoder, _ = zstd.NewReader(nil) |
|
|
|
|
|
|
|
func unzstdData(input []byte) ([]byte, error) { |
|
|
|
return decoder.DecodeAll(input, nil) |
|
|
|
} |
|
|
|
|
|
|
|
func IsGzippedContent(data []byte) bool { |
|
|
|
if len(data) < 2 { |
|
|
|
return false |
|
|
@ -95,12 +86,26 @@ func IsGzippedContent(data []byte) bool { |
|
|
|
return data[0] == 31 && data[1] == 139 |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
var zstdEncoder, _ = zstd.NewWriter(nil) |
|
|
|
|
|
|
|
func ZstdData(input []byte) ([]byte, error) { |
|
|
|
return zstdEncoder.EncodeAll(input, nil), nil |
|
|
|
} |
|
|
|
|
|
|
|
var decoder, _ = zstd.NewReader(nil) |
|
|
|
|
|
|
|
func unzstdData(input []byte) ([]byte, error) { |
|
|
|
return decoder.DecodeAll(input, nil) |
|
|
|
} |
|
|
|
|
|
|
|
func IsZstdContent(data []byte) bool { |
|
|
|
if len(data) < 4 { |
|
|
|
return false |
|
|
|
} |
|
|
|
return data[3] == 0xFD && data[2] == 0x2F && data[1] == 0xB5 && data[0] == 0x28 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
/* |
|
|
|
* Default not to compressed since compression can be done on client side. |
|
|
|