-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Milestone
Description
Although it is possible to retrieve the string that a Reader contains, it would be nice to avoid this and have direct access to the string that a Reader contains.
Therefore I propose the following:
// String always returns the string the Reader was initialized or reset with,
// irrelevant of any other method calls.
func (r *Reader) String() string {
return r.s
}
So the code required to get access to a Reader's content becomes:
Before:
r := strings.NewReader("hello")
var buf bytes.Buffer
r.Seek(0, io.SeekStart) // make sure we get the whole string)
io.Copy(&buf, r)
s := buf.String() // hello
After:
r := strings.NewReader("hello")
s := r.String() // hello
Reactions are currently unavailable