51 Star 428 Fork 194

Gitee 极速下载 / nps

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/cnlh/nps/
克隆/下载
snappy.go 825 Bytes
一键复制 编辑 原始数据 按行查看 历史
刘河 提交于 2019-03-29 10:44 . Snappy
package conn
import (
"github.com/cnlh/nps/lib/pool"
"github.com/cnlh/nps/vender/github.com/golang/snappy"
"io"
)
type SnappyConn struct {
w *snappy.Writer
r *snappy.Reader
}
func NewSnappyConn(conn io.ReadWriteCloser) *SnappyConn {
c := new(SnappyConn)
c.w = snappy.NewBufferedWriter(conn)
c.r = snappy.NewReader(conn)
return c
}
//snappy压缩写
func (s *SnappyConn) Write(b []byte) (n int, err error) {
if n, err = s.w.Write(b); err != nil {
return
}
if err = s.w.Flush(); err != nil {
return
}
return
}
//snappy压缩读
func (s *SnappyConn) Read(b []byte) (n int, err error) {
buf := pool.BufPool.Get().([]byte)
defer pool.BufPool.Put(buf)
if n, err = s.r.Read(buf); err != nil {
return
}
copy(b, buf[:n])
return
}
func (s *SnappyConn) Close() error {
s.w.Close()
return s.w.Close()
}
1
https://gitee.com/mirrors/nps.git
git@gitee.com:mirrors/nps.git
mirrors
nps
nps
v0.23.1

搜索帮助