Skip to content

Instantly share code, notes, and snippets.

@tientp-floware
Created March 5, 2020 02:44
Show Gist options
  • Save tientp-floware/ce6119c050d005566e8bb5f5110c14a7 to your computer and use it in GitHub Desktop.
Save tientp-floware/ce6119c050d005566e8bb5f5110c14a7 to your computer and use it in GitHub Desktop.
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()
}
@tientp-floware
Copy link
Author

I have improve and other way to convert.

func StreamToString(stream io.Reader) string {
     b, _ := ioutil.ReadAll(stream)
     
    return  string(b)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment