1 Star 0 Fork 0

wuzpdev/goworld

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
snappy.go 792 Bytes
Copy Edit Raw Blame History
seis authored 2017-10-11 13:49 . use config to set compress format
package compress
import (
"os"
"bytes"
"github.com/golang/snappy"
"github.com/xiaonanln/goworld/engine/gwioutil"
)
func NewSnappyCompressor() Compressor {
return &snappyCompressor{
writer: snappy.NewWriter(os.Stdout),
reader: snappy.NewReader(os.Stdin),
}
}
type snappyCompressor struct {
writer *snappy.Writer
reader *snappy.Reader
}
func (sc *snappyCompressor) Compress(b []byte, c []byte) ([]byte, error) {
wb := bytes.NewBuffer(c)
sc.writer.Reset(wb)
n, err := sc.writer.Write(b)
if err != nil {
return nil, err
}
if n != len(b) {
return nil, errNotFullyCompressed
}
sc.writer.Flush()
return wb.Bytes(), nil
}
func (sc *snappyCompressor) Decompress(c []byte, b []byte) error {
sc.reader.Reset(bytes.NewReader(c))
return gwioutil.ReadAll(sc.reader, b)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.2

Search

0d507c66 1850385 C8b1a773 1850385