bufio

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewScanner

func NewScanner() *scanner

NewScanner returns a new

Example (ReadFile)
package main

import (
	"fmt"
	"os"

	"github.com/brexhq/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() {
		fmt.Println(s.Text())
	}

	if err := s.Err(); err != nil {
		// handle error
		panic(err)
	}

}
Output:

foo
bar
baz
Example (Setup)
package main

import (
	"github.com/brexhq/substation/internal/bufio"
)

func main() {
	s := bufio.NewScanner()
	defer s.Close()
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL