Created
April 4, 2023 03:53
-
-
Save jrockway/959e448913ec184c2c86fbe6ab86238a to your computer and use it in GitHub Desktop.
URL safe base64 without padding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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