You almost never want bytes.NewBuffer. Its only purpose is to load a buffer with existing data to be read using Buffer.Read.
-rob On Tue, Oct 10, 2017 at 8:14 PM, <aurelien.rain...@gmail.com> wrote: > Oh yes, thank you. I totally missed that, thinking the bytes.Buffer was > preallocated with 4 bytes, instead i filled it with 4x0 bytes > > Le mardi 10 octobre 2017 10:59:56 UTC+2, Ian Davis a écrit : >> >> >> >> >> On Tue, 10 Oct 2017, at 09:51 AM, aurelien...@gmail.com wrote: >> >> >> func main() { >> buf := bytes.NewBuffer(make([]byte, 4)) >> buf.WriteString("1234") >> >> >> These two lines result in a string with 4 null bytes followed by 1234. >> Just use buf := &bytes.Buffer{} >> >> Ian >> >> >> >> >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.