代码拉取完成,页面将自动刷新
同步操作将从 John/gf 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright 2017 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://gitee.com/johng/gf.
// 数据压缩/解压
package gcompress
import (
"bytes"
"compress/zlib"
"compress/gzip"
"io"
)
// 进行zlib压缩
func Zlib(data []byte) []byte {
if data == nil || len(data) < 13 {
return data
}
var in bytes.Buffer
w := zlib.NewWriter(&in)
w.Write(data)
w.Close()
return in.Bytes()
}
// 进行zlib解压缩
func UnZlib(data []byte) []byte {
if data == nil || len(data) < 13 {
return data
}
b := bytes.NewReader(data)
var out bytes.Buffer
r, err := zlib.NewReader(b)
if err != nil {
return nil
}
io.Copy(&out, r)
return out.Bytes()
}
//做gzip解压缩
func UnGzip(data []byte) []byte {
var buf bytes.Buffer
content := bytes.NewReader(data)
zipdata, err := gzip.NewReader(content)
if err != nil {
return nil
}
io.Copy(&buf, zipdata)
zipdata.Close()
return buf.Bytes()
}
//做gzip压缩
func Gzip(data []byte) []byte {
var buf bytes.Buffer
zip := gzip.NewWriter(&buf)
_, err := zip.Write(data)
if err != nil {
return nil
}
zip.Close()
return buf.Bytes()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。