使用io.Pipe的困难之处

huangapple go评论102阅读模式
英文:

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

huangapple
  • 本文由 发表于 2022年9月6日 17:09:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/73619455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定