Home > Mobile >  Difficulty in using io.Pipe
Difficulty in using io.Pipe

Time:09-06

Hi friends I want to write a data in a writer and pass it to a library using a reader so that it can read Now the problem I have is that of png. Encode no longer continues and gets stuck there

r, w := io.Pipe()
err := png.Encode(w, img)

Tell me the solution if possible. Of course, I don't care if this problem is resolved, if you know another solution to the case that the data is written in a writer and read in a reader please suggest, there were secondary solutions, but I use two libraries that one just wants writer and one just reader.

CodePudding user response:

w is blocked waiting for a reader to read the data written to the pipe, thus blocking Encode

Reading from r will unblock Encode to the writer..

each Write to the PipeWriter blocks until it has satisfied one or more Reads from the PipeReader that fully consume the written data

  • Related