Skip to content

Instantly share code, notes, and snippets.

@bernardolm
Forked from tejainece/StreamToString.go
Created October 10, 2017 22:36
Show Gist options
  • Save bernardolm/1948152999baf86b80c56eed5c2894f1 to your computer and use it in GitHub Desktop.
Save bernardolm/1948152999baf86b80c56eed5c2894f1 to your computer and use it in GitHub Desktop.
Golang: io.Reader stream to string or byte slice
import "bytes"
func StreamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
func StreamToString(stream io.Reader) string {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment