Last active
December 28, 2019 13:01
-
-
Save kraxarn/963d909b917c463a6c782310eacdc09c to your computer and use it in GitHub Desktop.
Binary file to Go source file
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
/* | |
* Generate data | |
* | |
* Converts a file to a Go source file. | |
* Go source file gets generated as data.go with an appData constant containing the file data as base64. | |
* | |
* Licensed under WTFPL. | |
*/ | |
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
if len(os.Args) != 2 { | |
fmt.Println("usage: gendata <input>") | |
return | |
} | |
out, _ := ioutil.ReadFile(os.Args[1]) | |
data := fmt.Sprintf("package main\n\nconst appData = \"%v\"", base64.StdEncoding.EncodeToString(out)) | |
ioutil.WriteFile("data.go", []byte(data), 0644) | |
} |
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
/* | |
* Go to base64 | |
* | |
* Converts a file into a base64 string. | |
* Basically the same as base64, just made in Go to unsure compataiblity with Go applications. | |
* | |
* Licensed under WTFPL. | |
*/ | |
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
if len(os.Args) != 2 { | |
fmt.Println("usage: gotob64 <input>") | |
return | |
} | |
out, _ := ioutil.ReadFile(os.Args[1]) | |
fmt.Printf(base64.StdEncoding.EncodeToString(out)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment