Skip to content

Instantly share code, notes, and snippets.

@18o
Forked from tejainece/StreamToString.go
Created November 14, 2017 13:16
Show Gist options
  • Save 18o/eed0020381092e6c2affa950e59b78ad to your computer and use it in GitHub Desktop.
Save 18o/eed0020381092e6c2affa950e59b78ad 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