mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-13 09:48:17 +03:00
cmd: replace lua with base64
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package base64
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
xbase64 "github.com/xtls/xray-core/common/base64"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdEncode = &base.Command{
|
||||
UsageLine: "{{.Exec}} base64 encode [-gzip] [file | stdin:]",
|
||||
Short: "Encode as Base64",
|
||||
Long: fmt.Sprintf(`
|
||||
Encode a file or stdin: as Base64 with the %s prefix.
|
||||
Use -gzip to compress with gzip and output %s.
|
||||
|
||||
Examples:
|
||||
|
||||
{{.Exec}} base64 encode data.bin
|
||||
{{.Exec}} base64 encode -gzip data.bin
|
||||
{{.Exec}} base64 encode stdin:
|
||||
`, xbase64.Prefix, xbase64.GzipPrefix),
|
||||
}
|
||||
|
||||
var gzipEnabled = cmdEncode.Flag.Bool("gzip", false, "Compress the input with gzip.")
|
||||
|
||||
func init() {
|
||||
cmdEncode.Run = executeEncode
|
||||
}
|
||||
|
||||
func executeEncode(cmd *base.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
cmd.Usage()
|
||||
}
|
||||
data, err := readInput(args[0])
|
||||
if err != nil {
|
||||
base.Fatalf("failed to read input: %s", err)
|
||||
}
|
||||
value, err := xbase64.Encode(data, *gzipEnabled)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to encode input: %s", err)
|
||||
}
|
||||
if _, err := fmt.Fprintln(os.Stdout, value); err != nil {
|
||||
base.Fatalf("failed to write encoded output: %s", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user