go - io.Pipe使用困难

标签 go io pipe

嗨 friend 们我想在写入器中写入数据并使用读取器将其传递到库以便它可以读取 现在我遇到的问题是png。编码不再继续并卡在那里

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

如果可能的话请告诉我解决方案。当然,我不在乎这个问题是否得到解决,如果您知道数据在写入器中写入并在读取器中读取的情况的另一种解决方案,请提出建议,还有辅助解决方案,但我使用两个库,一个是只需要一位作家和一位读者。

最佳答案

w 被阻塞,等待读取器读取写入管道的数据,从而阻塞 Encode

r读取将解锁Encode写入器..

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

关于go - io.Pipe使用困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73619455/

相关文章:

angular - 为什么我应该在 Angular 订阅中使用 select with pipe?

go - 在 Go 代码中,如何在超时时终止进程及其子进程?

go - os.IsNotExist 但得到 "not a directory"

go - Rob Pike 在 Go 中的 "the synchronization nature of the channels"是什么意思?

bash - 提供管道 bash 脚本的选项

javascript - 将 JSON 对象转换为 pretty-print 的 JSON 的 Angular 2 管道

string - 从字符串到结构 Golang

Java 临时文件和自动删除

Java IO 线程安全

c++ - Linux : Will stat access Hard Disk for its operation