I'm trying to add a rot13 translation to my tool. Client basic code:
....
buf := make([]byte, 1024)
for {
n, err := in.Read(buf)
.....
for _, chunk := range split(r, buf[:n], sizes) {
if _, err := out.Write(chunk); err != nil {
......
Since I want it to work with bytes rather than strings, I came up with this:
https://play.golang.org/p/m3NvoZIyS8g
This example works, expect for some extra bytes which I don't understand, they are underlined with ***:
bytes after ***{***[89 111 117 32 99 114 97 99 107 101 100 32 116 104 101 32 99 111
100 101
32 32 32 32 32 32 32 239 191 189 85 239 191 189 239 191 189 239 191 189 74 40 239 191
189 47 239 191 189 86 239 191 189 45 239 191 189 33] ***0 0}***
string after ***{***You cracked the code �U���J(�/�V�-�! ***%!s(int=0)***
***%!s(bytes.readOp=0)}***
Please ignore the part with "�U���J(�/�V�-�!", I just needed some confirmation with this "string"
How do I get rid of this extra "stuff"? Is there any way to do my idea in a better way?
Those are remaining available bytes into the backing array of fub.
And because you print it raw, it shows all its internal.
You want to write : fmt.Printf("bytes after %v\n", fub.Bytes())
to get only the portion written onto it.
The same aplpies for the string representation, use fmt.Printf("string after %s\n\n", fub.String())