The-Golang-Standard-Library-by-Example
The-Golang-Standard-Library-by-Example copied to clipboard
有一个问题
sr := strings.NewReader("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
buf := bufio.NewReaderSize(sr, 0)
b := make([]byte, 10)
fmt.Println(buf.Buffered()) //
s, _ := buf.Peek(5)
s[0], s[1], s[2] = 'a', 'b', 'c'
fmt.Printf("%d %q\n", buf.Buffered(), s)
为啥使用了Peek 后 buf.Buffered()就不是0了。
因为Peek操作 会导致fill strings.NewReader的数据到bufio的buf中