I recently came across Open Sourcing: Base 64 Converter on steemit. Talk about a low quality post. Some people are just really reaching for content on steemit anymore.
Why Do I not Like This?
Well, it's a nothingburger. There is no point. Base64 is part of so many languages and tools. I do not see the need for this. Normally, I would not care, but this is one of those, "If you find this tool useful, look inward" situations. I want to use this opportunity to really help people rather than let this one go.
What is wrong with gnu?
cat file | base64 > file.b64
or
cat file.b64 | base64 -d > file
What is wrong with Python
cat file.b64 | python -c "import base64, sys; print(base64.b64decode(sys.stdin.read().strip()).decode('utf-8'))"
cat file | python -c "import base64, sys; print(base64.b64encode(sys.stdin.read().strip().encode('utf-8')).decode('utf-8'))"
What is wrong with NodeJS
cat file | node -e "process.stdin.on('data', d => console.log(Buffer.from(d).toString('base64')))"
cat file.b64 | node -e "process.stdin.on('data', d => console.log(Buffer.from(d.toString().trim(), 'base64').toString()))"
What is wrong with Golang
cat file | go run <(cat <<EOF
package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
)
func main() {
data, _ := ioutil.ReadAll(os.Stdin)
fmt.Println(base64.StdEncoding.EncodeToString(data))
}
EOF
)
cat file.b64 | go run <(cat <<EOF
package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
)
func main() {
data, _ := ioutil.ReadAll(os.Stdin)
decoded, _ := base64.StdEncoding.DecodeString(string(data))
fmt.Println(string(decoded))
}
EOF