The following code fails to read the line passed to stdin if the line is more too long:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
s := bufio.NewScanner(bufio.NewReader(os.Stdin))
s.Split(bufio.ScanLines)
s.Scan()
fmt.Printf("%v\n", len(s.Text()))
}
The expected output is line length, the actual output is 0. golang-issue.txt is file with single very long line. If the line is 65536 or less this code works ok, if it has more characters, the code fails.
Surprisingly, the second call to Scan() returns the complete line.
- go version go1.4.2 darwin/amd64
- OSX 10.10.3 (14D136)
- Program is started as follows:
go fmt golang-issue.go && go run golang-issue.go < golang-issue.txt