I'm using bufio.Scanner
, and I'm not sure if I should be giving it a reader wrapped by bufio.Reader
.
I.e., where f
is an os.File
, should I:
scanner := bufio.NewScanner(f)
or
scanner := bufio.NewScanner(bufio.NewReader(f))
I'm using bufio.Scanner
, and I'm not sure if I should be giving it a reader wrapped by bufio.Reader
.
I.e., where f
is an os.File
, should I:
scanner := bufio.NewScanner(f)
or
scanner := bufio.NewScanner(bufio.NewReader(f))
From the scan.go
source it doesn't look like you need to pass it a *bufio.Reader
: it has its own buffer, defaulting to 4K as bufio.Reader
's buffers do.
// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
return &Scanner{
r: r,
split: ScanLines,
maxTokenSize: MaxScanTokenSize,
buf: make([]byte, 4096), // Plausible starting size; needn't be large.
}
}