pax_global_header00006660000000000000000000000064133377012020014510gustar00rootroot0000000000000052 comment=b6e3aadd28864e14dae41ff5c7261455b1242d24 iochan-1.0.0/000077500000000000000000000000001333770120200127475ustar00rootroot00000000000000iochan-1.0.0/LICENSE.md000066400000000000000000000020751333770120200143570ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Mitchell Hashimoto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. iochan-1.0.0/README.md000066400000000000000000000004041333770120200142240ustar00rootroot00000000000000# iochan iochan is a Go library for treating `io` readers and writers like channels. This is useful when sometimes you wish to use `io.Reader` and such in `select` statements. ## Installation Standard `go get`: ``` $ go get github.com/mitchellh/iochan ``` iochan-1.0.0/go.mod000066400000000000000000000000431333770120200140520ustar00rootroot00000000000000module github.com/mitchellh/iochan iochan-1.0.0/iochan.go000066400000000000000000000015521333770120200145420ustar00rootroot00000000000000package 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 } iochan-1.0.0/iochan_test.go000066400000000000000000000006441333770120200156020ustar00rootroot00000000000000package iochan import ( "bytes" "reflect" "testing" ) func TestDelimReader(t *testing.T) { buf := new(bytes.Buffer) buf.WriteString("foo\nbar\nbaz") ch := DelimReader(buf, '\n') results := make([]string, 0, 3) expected := []string{"foo\n", "bar\n", "baz"} for v := range ch { results = append(results, v) } if !reflect.DeepEqual(results, expected) { t.Fatalf("unexpected results: %#v", results) } }