Why doesn't everything be read out after using peek in bufio? What should be understood by peek?

package main

import (
    "os"
    "bufio"
    "fmt"
    "io/ioutil"
)

func main()  {
    f,err := os.Open("b.txt")
    if err != nil {
        panic(err)
    }
    
     _,err= bufio.NewReader(f).Peek(64)
    if err != nil {
        panic(err)
    }
    r,err:=ioutil.ReadAll(f)
    if err != nil {
        panic(err)
    }
     fmt.Println(string(r))
}

it is written on the document that peek will not move the read position, so why is it that my code above does not read everything? But the rest of the content
peek how to understand?

here is the explanation of the peek function on the official website

clipboard.png


package main

import (
    "os"
    "bufio"
    "fmt"
    "io/ioutil"
)

func main()  {
    f,err := os.Open("b.txt")
    if err != nil {
        panic(err)
    }

    nReader := bufio.NewReader(f)
    _,err = nReader.Peek(64)
     //_,err= bufio.NewReader(f).Peek(64)
    if err != nil {
        panic(err)
    }
     r,err:=ioutil.ReadAll(nReader)
    if err != nil {
        panic(err)
    }
     fmt.Println(string(r))
}
The

problem is solved. Peek is for Reader, so it's the Reader object that should be manipulated, not f

.
Menu