On Thu, 13 Oct 2016 10:43:24 -0700 (PDT) Walter Garcia <wal...@gmail.com> wrote:
> Im trying to test using zlib. > > In my test I need compress the Stdout from exec.Command to zlib and > then send to io.reader to use in other service > > cmd := exec.Command("mysqldump", args...) > ...... > cmd.StdoutPipe() > > z := zlib.NewWriter( ... ) > ..... > z -> to -> io.reader > > Could you help me? You can't do that directly because you can only write to io.Writer-s. This is reasonable if you stop and think about it for a moment: an io.Writer is a "push-style" interface -- you write something to whatever is implementing it and block until that action happens; -- conversely, io.Reader is a "pull-style" interface -- you read something from a source and that blocks until the source is ready. To glue a writer and a reader you need some intermediate "thing" which would simultaneostly be a reader and a writer (!) -- so that it satisfies both kinds of interfaces described above. Such things are called "pipes" and Go provides at least two of them: * io.Pipe is a pure-Go pipe; * os.Pipe is a pipe provided by the underlying kernel. The former is supposedly what you need. Still note that to make z -> pipe -> io.reader really work the "z" and the "io.reader" parts have to be in separate goroutines otherwise they will block one another. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.