互连流
我有这样的场景:
DownloadLibrary.GetData(Stream targetStream);
SaveLibrary.WriteData(Stream sourceStream);
我想将targetStream收集的数据发送到sourceStream。我已经提出了一些解决方案,但我找不到直接连接这些流的方法。
我想要实现的是将数据从 targetStream 发送到 sourceStream,而不首先缓冲 targetStream。
怎么办呢?
提前致谢。
I have this scenario:
DownloadLibrary.GetData(Stream targetStream);
SaveLibrary.WriteData(Stream sourceStream);
I want to send the data that targetStream collects to the sourceStream. I've come up with some solutions but I cannot find a way to connect those streams directly.
What I'm trying to achieve is send the data from targetStream to sourceStream without buffer the targetStream first.
How can it be done?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Stream
中内置支持(从 .Net 4.0 开始),可通过CopyTo
将一个流复制到另一个流,例如:示例:
There is built in support (from .Net 4.0) in
Stream
for copying one stream to another viaCopyTo
, e.g.:Example:
chibacity 的答案中提到的内置 CopyTo 方法可从 .NET 4.0 获得。
对于早期版本,请查看此问题。
The built-in CopyTo method referred to in chibacity's answer is available from .NET 4.0.
For earlier versions look at this question.