drain

package module
v0.0.0-...-c007e9a Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2016 License: BSD-3-Clause Imports: 4 Imported by: 1

README

go-drain

A Go library for connecting Readers and Writers with string channels, with convenience functions for os.Stdin, os.Stdout, and os.File.

The go-drain-example app demonstrates practical use of this package.

Online GoDoc

https://godoc.org/github.com/momokatte/go-drain

Documentation

Index

Examples

Constants

View Source
const (
	NewLineString     = string(0x0A)
	DefaultBufferSize = 64 * 1024
)

Variables

This section is empty.

Functions

func ChanToBufioWriter

func ChanToBufioWriter(source <-chan string, separator string, bw *bufio.Writer) (err error)

Writes all strings from a channel to a bufio.Writer until the channel is closed. When the channel is empty, the buffer is flushed to the underlying io.Writer and the execution thread is yielded to another goroutine.

func ChanToFile

func ChanToFile(source <-chan string, fileName string) error

Writes all strings from a channel to a File, with trailing newline characters, until the channel is closed. Uses the default buffer size.

func ChanToFileSize

func ChanToFileSize(source <-chan string, bufSize int, fileName string) (err error)

Writes all strings from a channel to a File, with trailing newline characters, until the channel is closed. The file will be created if it does not exist, and appended to if it already exists.

func ChanToStdout

func ChanToStdout(source <-chan string) error

Writes all strings from a channel to os.Stdout, with trailing newline characters, until the channel is closed. Uses the default buffer size.

Example
c := make(chan string, 2)
go func() {
	for _, s := range []string{"abcde", "fghij", "klmno", "pqrst"} {
		c <- s
	}
	close(c)
}()

ChanToStdout(c)
Output:

abcde
fghij
klmno
pqrst

func ChanToStdoutSize

func ChanToStdoutSize(source <-chan string, bufSize int) error

Writes all strings from a channel to os.Stdout, with trailing newline characters, until the channel is closed.

func ChanToWriter

func ChanToWriter(source <-chan string, separator string, w io.Writer) (err error)

Writes all strings from a channel to an io.Writer until the channel is closed. When the channel is empty, the execution thread is yielded to another goroutine.

func FileLinesToChan

func FileLinesToChan(fileName string, dest chan<- string) error

Scans all lines from a File into a channel until EOF

func FileToChan

func FileToChan(fileName string, split bufio.SplitFunc, dest chan<- string) (err error)

Scans all tokens from a File into a channel until EOF

func ReaderToChan

func ReaderToChan(r io.Reader, split bufio.SplitFunc, dest chan<- string) error

Scans all tokens from an io.Reader into a channel until EOF

func ScannerToChan

func ScannerToChan(s *bufio.Scanner, dest chan<- string) error

Scans all tokens into a channel until EOF

func StdinLinesToChan

func StdinLinesToChan(dest chan<- string) error

Scans all lines from os.Stdin into a channel until EOF

func StdinToChan

func StdinToChan(split bufio.SplitFunc, dest chan<- string) error

Scans all tokens from os.Stdin into a channel until EOF

func StdinWordsToChan

func StdinWordsToChan(dest chan<- string) error

Scans all words from os.Stdin into a channel until EOF

Types

This section is empty.

Jump to

Keyboard shortcuts

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