Skip to content

Instantly share code, notes, and snippets.

@jrockway
Created April 4, 2023 03:53
Show Gist options
  • Save jrockway/959e448913ec184c2c86fbe6ab86238a to your computer and use it in GitHub Desktop.
Save jrockway/959e448913ec184c2c86fbe6ab86238a to your computer and use it in GitHub Desktop.
URL safe base64 without padding
package main
import (
"encoding/base64"
"io"
"log"
"os"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "-d" {
d := base64.NewDecoder(base64.RawURLEncoding, os.Stdin)
if _, err := io.Copy(os.Stdout, d); err != nil {
log.Fatal(err)
}
if err := os.Stdout.Close(); err != nil {
log.Fatal(err)
}
} else {
e := base64.NewEncoder(base64.RawURLEncoding, os.Stdout)
if _, err := io.Copy(e, os.Stdin); err != nil {
log.Fatal(err)
}
if err := e.Close(); err != nil {
log.Fatal(err)
}
if err := os.Stdout.Close(); err != nil {
log.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment