improve package gcompress

This commit is contained in:
John
2020-05-01 01:47:02 +08:00
parent f7c2a51c9f
commit cc67f3d388
2 changed files with 31 additions and 11 deletions

View File

@ -1,13 +1,29 @@
package main
import (
"encoding/hex"
"fmt"
"github.com/gogf/gf/os/gtimer"
"time"
"github.com/gogf/gf/encoding/gbase64"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/grand"
)
func main() {
tr := gtimer.New(100, 1*time.Second, 10)
tr.Add(1*time.Second, func() { fmt.Println("hello") })
select {}
// bytesToHexString converts binary content to hex string content.
func bytesToHexStr(b []byte) string {
dst := make([]byte, hex.EncodedLen(len(b)))
hex.Encode(dst, b)
return gconv.UnsafeBytesToStr(dst)
}
func main() {
b := make([]byte, 1024)
for i := 0; i < 1024; i++ {
b[i] = byte(grand.N(0, 255))
}
fmt.Println(bytesToHexStr(b))
fmt.Println(len(b))
fmt.Println(len(bytesToHexStr(b)))
fmt.Println(gbase64.EncodeToString(b))
fmt.Println(len(gbase64.EncodeToString(b)))
}