-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdio.go
42 lines (35 loc) · 1.2 KB
/
stdio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2015 Michael O'Rourke. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package drain
import (
"bufio"
"os"
)
// Scans all lines from os.Stdin into a channel until EOF
//
func StdinLinesToChan(dest chan<- string) error {
return StdinToChan(bufio.ScanLines, dest)
}
// Scans all words from os.Stdin into a channel until EOF
//
func StdinWordsToChan(dest chan<- string) error {
return StdinToChan(bufio.ScanWords, dest)
}
// Scans all tokens from os.Stdin into a channel until EOF
//
func StdinToChan(split bufio.SplitFunc, dest chan<- string) error {
return ReaderToChan(os.Stdin, split, dest)
}
// Writes all strings from a channel to os.Stdout, with trailing newline characters, until the channel is closed.
// Uses the default buffer size.
//
func ChanToStdout(source <-chan string) error {
return ChanToStdoutSize(source, DefaultBufferSize)
}
// Writes all strings from a channel to os.Stdout, with trailing newline characters, until the channel is closed.
//
func ChanToStdoutSize(source <-chan string, bufSize int) error {
bw := bufio.NewWriterSize(os.Stdout, bufSize)
return ChanToBufioWriter(source, NewLineString, bw)
}