Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Golang ReadWriteCloser as io.File

$
0
0

In golang having an instance of io.ReadWriteCloser how to obtain its representation (kind of proxy) as an instance of *os.File (E.g. to be provided for exec.Cmd.ExtraFiles)

The first is coming to a mind is to use os.Pipe approach. Still such a stub would be unidirectional (read or write only).

So how to completely represent io.ReadWriteCloser as an *os.FileE.g.

func something(stream io.ReadWriteCloser) {  cmd := exec.Command("comm")  var wrapped *os.File = wrappAsFile(stream) // How this could be achieved?  cmd.ExtraFiles := []*File{wrapped}}

Simplified solution I can see would be something like the following. Still (as I mentioned it before) it covers only a Reader flow.

func something(stream io.ReadWriteCloser) {  cmd := exec.Command("comm")  r, w, _ := os.Pipe()  go func() {     io.Copy(w, stream)     w.Close()  }()  cmd.ExtraFiles := []*File{r}}

Thx


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>