Last active
August 29, 2015 14:10
-
-
Save jamesduncombe/e151ccaa8507c548ab9e to your computer and use it in GitHub Desktop.
Quick base64 convertor in Go
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" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"mime" | |
"path/filepath" | |
"strings" | |
) | |
func main() { | |
flag.Parse() | |
args := flag.Arg(0) | |
bytes, err := ioutil.ReadFile(args) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("data:%s;base64,%s\n", mime.TypeByExtension(filepath.Ext(args)), strings.TrimSpace(base64.StdEncoding.EncodeToString(bytes))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment