Standard library / bufio

bufio.Scanner.Buffer()

Sets scratch buffer and maximum token-buffer size before scanning starts. Calling after Scan panics. Expected stdout: 'true 70000 <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func (s *Scanner) Buffer(buf []byte, max int)

Parameters & Attributes

NameTypeDescription
buf[]byteCaller-supplied byte buffer.
maxintMaximum token-buffer size.

Working Example

Example Snippetgo
package main
import (  "bufio"  "fmt"  "strings")
func main() {  s := bufio.NewScanner(strings.NewReader(strings.Repeat("a", 70000)))  s.Buffer(make([]byte, 1024), 100000)  fmt.Println(s.Scan(), len(s.Bytes()), s.Err())}
Go Reference