// NewReaderSize returns a new Reader whose buffer has at least the specified
43 // size. If the argument io.Reader is already a Reader with large enough
44 // size, it returns the underlying Reader.
45 func NewReaderSize(rd io.Reader, size int) *Reader {
46 // Is it already a Reader?
47 b, ok := rd.(*Reader)
48 if ok && len(b.buf) >= size {
49 return b
50 }
51 if size < minReadBufferSize {
52 size = minReadBufferSize
53 }
54 r := new(Reader)
55 r.reset(make([]byte, size), rd)
56 return r
57 }
When I use os.Open to open a file
dictFile, err := os.Open(file)
I'm going to pass dicFile to
reader := bufio.NewReader(dictFile)
I found the underlying code is using func NewReaderSize
, but what I can not understand is rd.(*Reader)
. Reader
is the struct type contained in package bufio
. Asterisk followed by a struct is from what I see to get the value from pointer Reader
, but it is not a pointer, so it does not make sense. Further more, it's using dot operator rd.(*Reader)
, I totally got confused. What's the meaning of this kind of usage in line 47? What kind of notation it is?