I am encoding an executable in go
and trying to decode it in javascript
.
Decoding the encoded string
in javascript
does not result in a matching file. I am able to encode a string like "this is a test string"
and decode it in javascript
and it works fine. But when i take an executable application and do the same thing, the decoded file is larger than the file before encoding.
What am i doing wrong? Thanks!
Here is the test executable i am using. It is in c++, compile it with g++
and use the output.
#include <iostream>
int main(void) {
char test1[] = "hello";
std::cout << "test1: " << test1 << std::endl;
char test2[] = "world";
std::cout << "test2: " << test2 << std::endl;
char test3[] = "foobar";
std::cout << "test3: " << test3 << std::endl;
return 0;
}
Here is the go
app i am using to convert the file to bytes
.
package main
import (
"fmt"
"github.com/atotto/clipboard"
"io/ioutil"
)
func main() {
bytes, err := ioutil.ReadFile("/path/to/file/a.out")
if err != nil {
fmt.Println(err)
}
enc := make([]byte, base64.RawStdEncoding.EncodedLen(len(bytes)))
base64.RawStdEncoding.Encode(enc, bytes)
fmt.Println("byte size: ", len(bytes))
fmt.Println("encoded byte size: ", len(enc))
clipboard.WriteAll(string(enc))
}
Here is how i am attempting to decode and save the file in javascript.
let decodedBytes = atob("put the bytes here from your clipboard from running the go app");
fs.writeFileSync(
"/destination/to/save/file",
decodedBytes
);