Skip to content

Instantly share code, notes, and snippets.

@toannd96
Forked from dixudx/StreamToString.go
Created April 15, 2021 08:29
Show Gist options
  • Save toannd96/3f6fccc9c09163b4fd97d870d83bee70 to your computer and use it in GitHub Desktop.
Save toannd96/3f6fccc9c09163b4fd97d870d83bee70 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