The-Golang-Standard-Library-by-Example icon indicating copy to clipboard operation
The-Golang-Standard-Library-by-Example copied to clipboard

有一个问题

Open Devying opened this issue 6 years ago • 1 comments

        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了。

Devying avatar Jan 31 '19 10:01 Devying

因为Peek操作 会导致fill strings.NewReader的数据到bufio的buf中

Himer avatar Jun 05 '19 12:06 Himer