1 Star 0 Fork 0

hbgo/dameng

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
f.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
VioletFlame 提交于 2024-11-04 15:58 . init
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package godm
import (
"bytes"
"compress/zlib"
"github.com/golang/snappy"
)
func Compress(srcBuffer *Dm_build_1290, offset int, length int, compressID int) ([]byte, error) {
if compressID == Dm_build_374 {
return snappy.Encode(nil, srcBuffer.Dm_build_1584(offset, length)), nil
}
return GzlibCompress(srcBuffer, offset, length)
}
func UnCompress(srcBytes []byte, compressID int) ([]byte, error) {
if compressID == Dm_build_374 {
return snappy.Decode(nil, srcBytes)
}
return GzlibUncompress(srcBytes)
}
func GzlibCompress(srcBuffer *Dm_build_1290, offset int, length int) ([]byte, error) {
var ret bytes.Buffer
var w = zlib.NewWriter(&ret)
w.Write(srcBuffer.Dm_build_1584(offset, length))
w.Close()
return ret.Bytes(), nil
}
func GzlibUncompress(srcBytes []byte) ([]byte, error) {
var bytesBuf = new(bytes.Buffer)
r, err := zlib.NewReader(bytes.NewReader(srcBytes))
if err != nil {
return nil, err
}
defer r.Close()
_, err = bytesBuf.ReadFrom(r)
if err != nil {
return nil, err
}
return bytesBuf.Bytes(), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hbgo/dameng.git
git@gitee.com:hbgo/dameng.git
hbgo
dameng
dameng
v1.0.4

搜索帮助