Re: [go-nuts] efficient way to csv.Reader() from a chan of string

2018-09-17 Thread 'Bryan Mills' via golang-nuts
You don't need the io.Pipe: it's fairly trivial to implement io.Reader in terms of a channel of strings and a strings.Reader. You can even implement io.WriterTo efficiently that way: https://play.golang.org/p/PxIEQYUoC50 (In theory that can make the whole pipeline zero-copy, but in practice I

Re: [go-nuts] efficient way to csv.Reader() from a chan of string

2018-09-16 Thread Sherif Eldeeb
Even though Yannic's answer was really useful and appreciated, I ended up using io.Pipe() which looks simpler and more efficient (explained below): rp, wp := io.Pipe() go func() { defer wp.Close() for i := range feederChan { fmt.Fprintln(wp, i) } }(

Re: [go-nuts] efficient way to csv.Reader() from a chan of string

2018-09-15 Thread Yannic Bonenberger
You can use a bytes.Buffer to create a single csv.Reader and write the log lines into that buffer. The code will look roughly like this https://play.golang.org/p/gbCPwSsx5gy . However, depending on the implementation of strings.Reader and the level of optimization the Go compiler does, your appro

[go-nuts] efficient way to csv.Reader() from a chan of string

2018-09-15 Thread Sherif Eldeeb
Greetings all, I have a channel of 'string', where each item is a single CSV log line that I want to convert to columns using "encoding/csv" Currently, I am creating a new csv.Reader at each iteration for each item, which is much more work than it needs to be. for i := range feederChan {