-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adaptive):add new compression algorithm——zstd.
- Loading branch information
1 parent
a30823b
commit a2afc41
Showing
8 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package zstd | ||
|
||
import ( | ||
"github.com/klauspost/compress/zstd" | ||
) | ||
|
||
func NewDecompressor() *ZstdDecompressor { | ||
decoder, _ := zstd.NewReader(nil) | ||
return &ZstdDecompressor{ | ||
decoder: decoder, | ||
} | ||
} | ||
|
||
type ZstdDecompressor struct { | ||
decoder *zstd.Decoder | ||
} | ||
|
||
// this will return a original data. | ||
func (c *ZstdDecompressor) Decompress(dst, src []byte) []byte { | ||
ans, err := c.decoder.DecodeAll(src, dst) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package zstd | ||
|
||
import ( | ||
"github.com/klauspost/compress/zstd" | ||
) | ||
|
||
func NewCompressor() *ZstdCompressor { | ||
encoder, _ := zstd.NewWriter(nil) | ||
return &ZstdCompressor{ | ||
encoder: encoder, | ||
} | ||
} | ||
|
||
type ZstdCompressor struct { | ||
encoder *zstd.Encoder | ||
} | ||
|
||
// this will return a zstd format data. | ||
func (c *ZstdCompressor) Compress(src []byte) []byte { | ||
return c.encoder.EncodeAll(src, make([]byte, 0, len(src))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters