mirror of
https://gitee.com/johng/gf
synced 2026-07-06 13:42:46 +08:00
improve package gcompress
This commit is contained in:
@ -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)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user