Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( Base64Decode base64DecodeFlag = true Base64NoDecode base64DecodeFlag = false )
const ( Base64IgnoreGarbage base64IgnoreGarbageFlag = true Base64NoIgnoreGarbage base64IgnoreGarbageFlag = false )
Variables ¶
This section is empty.
Functions ¶
func Base64 ¶
Base64 returns a command that base64-encodes or -decodes its whole input, matching GNU coreutils base64.
Encode (default): the entire input is treated as one byte stream and encoded; output is wrapped at column 76, or at the column given by Base64Wrap(COLS). Base64Wrap(0) disables wrapping.
Decode (Base64Decode / -d): the entire input is concatenated and decoded. Without Base64IgnoreGarbage, a byte outside the base64 alphabet is an error; with it (-i / --ignore-garbage), such bytes are discarded before decoding.
Example ¶
package main
import (
"fmt"
"github.com/gloo-foo/testable"
command "github.com/gloo-foo/cmd-base64"
)
func main() {
lines, _ := testable.TestLines(command.Base64(), "Hello World\n")
for _, line := range lines {
fmt.Println(line)
}
}
Output: SGVsbG8gV29ybGQ=
Example (Decode) ¶
package main
import (
"fmt"
"github.com/gloo-foo/testable"
command "github.com/gloo-foo/cmd-base64"
)
func main() {
lines, _ := testable.TestLines(command.Base64(command.Base64Decode), "SGVsbG8gV29ybGQ=\n")
for _, line := range lines {
fmt.Println(line)
}
}
Output: Hello World
Example (Wrap) ¶
package main
import (
"fmt"
"github.com/gloo-foo/testable"
command "github.com/gloo-foo/cmd-base64"
)
func main() {
lines, _ := testable.TestLines(command.Base64(command.Base64Wrap(10)), "Hello World\n")
for _, line := range lines {
fmt.Println(line)
}
}
Output: SGVsbG8gV2 9ybGQ=
Types ¶
type Base64Wrap ¶
type Base64Wrap uint
Base64Wrap sets the column at which encoded output is wrapped (-w / --wrap). Base64Wrap(0) disables wrapping. When no Base64Wrap is supplied the GNU default of 76 applies (see defaultWrap).