You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
running go1.1beta2.linux-amd64
Just a few issues regarding bufio Scanner and zero length reads of the underlying io.Reader.
1. It is not documented that the scanner also stops on a zero length read.
2. If the underlying reader returns a zero length read with an error that is
not io.EOF the error is masked and Err() returns nil.
Eg, this program will not print out the error.
package main
import (
"bufio"
"errors"
"fmt"
)
type errReader struct{}
func (t *errReader) Read(p []byte) (int, error) {
return 0, errors.New("Random Err")
}
func main() {
scanner := bufio.NewScanner(new(errReader))
for scanner.Scan() {
fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
}
}
3. I don't see in any of the other standard library readers documentation
that they guarantee no zero length reads. If I am being paranoid, can
I safely use them without the scan prematurely terminating before EOF?
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: