Skip to content

Instantly share code, notes, and snippets.

@dixudx
Forked from tejainece/StreamToString.go
Created November 16, 2016 09:34
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dixudx/3989284b142414e10352fde9def5c771 to your computer and use it in GitHub Desktop.
Save dixudx/3989284b142414e10352fde9def5c771 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