Documentation ¶
Overview ¶
package bufio wraps the standard library's bufio package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewScanner ¶
func NewScanner() *scanner
NewScanner returns a new scanner with default settings provided by scanCapacity and scanMethod.
Example (ReadFile) ¶
package main import ( "fmt" "os" "github.com/jshlbrd/substation/internal/bufio" ) func main() { // temp file is used to simulate an open file and must be removed after the test completes file, _ := os.CreateTemp("", "substation") defer os.Remove(file.Name()) _, _ = file.Write([]byte("foo\nbar\nbaz")) // scanner closes all open handles, including the open file s := bufio.NewScanner() defer s.Close() // scanner automatically decompresses file and chooses appropriate scan method (default is "text") if err := s.ReadFile(file); err != nil { // handle error panic(err) } for s.Scan() { switch s.Method() { case "bytes": fmt.Println(s.Bytes()) case "text": fmt.Println(s.Text()) } } }
Output: foo bar baz
Example (Setup) ¶
package main import ( "github.com/jshlbrd/substation/internal/bufio" ) func main() { s := bufio.NewScanner() defer s.Close() // sets maximum capacity to 1024 bytes // defaults to 65536 bytes s.SetCapacity(1024) // sets method to "bytes" // defaults to "text" if err := s.SetMethod("bytes"); err != nil { // handle error panic(err) } }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.