示例#1
0
func tsetCompressor(compressor func(inb []byte) (outb []byte), decompressor func(inb []byte) (outb []byte)) {
	origin := []byte("123")
	ob := compressor([]byte("123"))
	output := decompressor(ob)
	kmgTest.Equal(origin, output)

	//for i:=1;i<20;i++ {
	//	fmt.Println(kmgHex.UpperEncodeBytesToString(compressor(bytes.Repeat([]byte{'1'},i))))
	//}
	//for i:=1;i<100;i++ {
	//	fmt.Println(kmgHex.UpperEncodeBytesToString(compressor(kmgRand.MustCryptoRandBytes(i))))
	//}
	for _, i := range []int{1, 10, 100, 1000, 1e4, 1e5} {
		ob = compressor(kmgRand.MustCryptoRandBytes(i))
		fmt.Println(i, len(ob), len(ob)-i)
	}
	for _, path := range []string{
		"/Users/bronze1man/tmp/vanke.sql",
		"/bin/kmg",
	} {
		c := kmgFile.MustReadFile(path)
		t := time.Now()
		ob = compressor(c)
		dur := time.Since(t)
		fmt.Println(path, kmgNet.SizeString(int64(len(c))), kmgNet.SizeString(int64(len(ob))),
			float64(len(ob))/float64(len(c)), dur)
	}

	fmt.Println()
}
示例#2
0
文件: goHttp.go 项目: keysonZZZ/kmg
func printProgress(get int64, total int64, dur time.Duration, lastBytes int) {
	percent := 0.0
	if total <= 0 {
		percent = 0.0
	} else if total < get {
		percent = 1.0
	} else {
		percent = float64(get) / float64(total)
	}
	showNum := int(percent * 40)
	notShowNum := 40 - showNum
	fmt.Printf("%s%s %.2f%% %s/%s %s     \r",
		strings.Repeat("#", showNum), strings.Repeat(" ", notShowNum), percent*100,
		kmgNet.SizeString(get), kmgNet.SizeString(total), kmgNet.SpeedString(lastBytes, dur))
}