1 Star 0 Fork 12

xp_hust / CloudStore

forked from 进击的皇虫 / CloudStore 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
TruthHun 提交于 2019-03-17 22:55 . 百度云存储只是ContenEncoding
package CloudStore
import (
"bytes"
"compress/gzip"
"crypto/md5"
"encoding/hex"
"encoding/json"
"io/ioutil"
"os"
"strings"
)
var (
sevenDays int64 = 7 * 24 * 3600
)
// 绝对路径,abs => absolute
func objectAbs(object string) string {
return "/" + strings.TrimLeft(object, " ./")
}
// 相对路径 rel => relative
func objectRel(object string) string {
return strings.TrimLeft(object, " ./")
}
// MD5 Crypt
func MD5Crypt(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func CompressByGzip(tmpFile, saveFile string) (err error) {
var (
input []byte
buf bytes.Buffer
)
input, err = ioutil.ReadFile(tmpFile)
if err != nil {
return
}
writer, _ := gzip.NewWriterLevel(&buf, gzip.BestCompression)
defer writer.Close()
writer.Write(input)
writer.Flush()
err = ioutil.WriteFile(saveFile, buf.Bytes(), os.ModePerm)
return
}
func toJSON(v interface{}) (jsonStr string) {
p, err := json.Marshal(v)
if err != nil {
return
}
return string(p)
}
Go
1
https://gitee.com/xphust/CloudStore.git
git@gitee.com:xphust/CloudStore.git
xphust
CloudStore
CloudStore
master

搜索帮助