You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Victorique/vtqe/tools/base64.go

62 lines
1.4 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package tools
import (
"fmt"
"b612.me/starainrt"
"b612.me/starlog"
"github.com/spf13/cobra"
)
var b64cmd = &cobra.Command{
Use: "base64",
Short: "使用base64处理文件或字符串",
Long: "使用base64处理文件或字符串",
Run: func(this *cobra.Command, args []string) {
var err error
ok, _ := this.Flags().GetBool("file")
de, _ := this.Flags().GetBool("decode")
if len(args) != 1 {
starlog.StdPrintln(0, starlog.RED, "参数不足,请输入文件地址或字符串")
this.Help()
return
}
shell := func(pect float64) {
if pect == 100 {
fmt.Println("已处理100.000000%")
} else {
fmt.Printf("已处理:%f%%\r", pect)
}
}
cry := new(starainrt.StarCrypto)
if ok {
path, _ := this.Flags().GetString("path")
if !de {
err = cry.Base64EncodeFile(args[0], path, shell)
} else {
err = cry.Base64DecodeFile(args[0], path, shell)
}
} else {
if !de {
data := cry.Base64Encode([]byte(args[0]))
fmt.Println(data)
} else {
var data []byte
data, err = cry.Base64Decode(args[0])
fmt.Println(string(data))
}
}
if err != nil {
starlog.StdPrintln(0, starlog.RED, err)
return
}
},
}
func init() {
b64cmd.Flags().BoolP("file", "f", false, "base64处理文件")
b64cmd.Flags().StringP("path", "p", "./b64.encode", "指定处理地址,默认为./b64.encode")
b64cmd.Flags().BoolP("decode", "d", false, "base64解码")
Maincmd.AddCommand(b64cmd)
}