/usr/share/gocode/src/github.com/mitchellh/iochan/iochan.go is in golang-github-mitchellh-iochan-dev 0.0~git20150529.0.87b45ff-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | package iochan
import (
"bufio"
"io"
)
// DelimReader takes an io.Reader and produces the contents of the reader
// on the returned channel. The contents on the channel will be returned
// on boundaries specified by the delim parameter, and will include this
// delimiter.
//
// If an error occurs while reading from the reader, the reading will end.
//
// In the case of an EOF or error, the channel will be closed.
//
// This must only be called once for any individual reader. The behavior is
// unknown and will be unexpected if this is called multiple times with the
// same reader.
func DelimReader(r io.Reader, delim byte) <-chan string {
ch := make(chan string)
go func() {
buf := bufio.NewReader(r)
for {
line, err := buf.ReadString(delim)
if line != "" {
ch <- line
}
if err != nil {
break
}
}
close(ch)
}()
return ch
}
|