英文:
Difficulty in using io.Pipe
问题
嗨朋友们,我想将数据写入一个写入器(writer),然后通过一个读取器(reader)将其传递给一个库,以便它可以读取。现在我遇到的问题是关于PNG格式的。编码(png.Encode)不再继续执行,而是停在那里。
告诉我可能的解决方案。当然,如果你知道在数据写入写入器(writer)并在读取器(reader)中读取的情况下的其他解决方案,请提供建议。有一些次要的解决方案,但我使用了两个库,其中一个只需要写入器(writer),另一个只需要读取器(reader)。
英文:
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.
答案1
得分: 2
w
被阻塞,等待读取器读取写入管道的数据,从而阻塞了 Encode
。
从 r
读取将解除对写入器 Encode
的阻塞。
每次写入 PipeWriter
都会阻塞,直到满足一个或多个从 PipeReader
读取的条件,完全消耗写入的数据。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论