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
func main() {
reader := bufio.NewReader(strings.NewReader("abcdefghijklmnopqrstuvwxyz" + strings.Repeat("a", 1000000)))
line, isPrefix, _ := reader.ReadLine()
// "abcdefghijklmnopqrstuvwxyz" => correct
fmt.Printf("Prefix of 'line' after the first call to ReadLine() %v\n", line[:26])
for isPrefix {
var tmp []byte
tmp, isPrefix, _ = reader.ReadLine()
line = append(line, tmp...)
}
// TODO: Why not "abcdefghijklmnopqrstuvwxyz" ???
fmt.Printf("Prefix of 'line' after complete reading a line %v\n", line[:26])
fmt.Println(len(line)) // 1000026
}
What did you see happen?
Prefix of 'line' after the first call to ReadLine() [97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122]
Prefix of 'line' after complete reading a line [97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97]
1000026
What did you expect to see?
Prefix of 'line' after the first call to ReadLine() [97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122]
Prefix of 'line' after complete reading a line [97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122]
1000026
The text was updated successfully, but these errors were encountered:
The returned buffer is only valid until the next call to ReadLine
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
Go version
Go 1.21 (go.dev/play)
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/W_LvqY2Qu84
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: