我怎么能分裂(复制)在.NET中的流? [英] How can I split (copy) a Stream in .NET?

查看:133
本文介绍了我怎么能分裂(复制)在.NET中的流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道在哪里可以找到一个分流器的实现?

Does anyone know where I can find a Stream splitter implementation?

我期待的是流,并获得两个单独的流可以独立阅读,并不会影响对方休息。这些流应该在每次返回相同的二进制数据的原始数据流会。无需执行位置或寻求与这样的......仅向前。

I'm looking to take a Stream, and obtain two separate streams that can be independently read and closed without impacting each other. These streams should each return the same binary data that the original stream would. No need to implement Position or Seek and such... Forward only.

我倒是preFER如果它不只是全码流复制到内存中,并为它服务了多次,这将是相当足够简单,实现自己。

I'd prefer if it didn't just copy the whole stream into memory and serve it up multiple times, which would be fairly simple enough to implement myself.

有什么在那里,能做到这一点?

Is there anything out there that could do this?

推荐答案

不开箱。

您需要从以FIFO方式原始流缓冲区中的数据,仅丢弃已经阅读所有读者流数据。

You'll need to buffer the data from the original stream in a FIFO manner, discarding only data which has been read by all "reader" streams.

我会使用:

  • 系统管理对象持有某种拿着被缓冲块和读取源数据流的附加数据字​​节[]队列中,如果需要
  • 在其中已知的地点和什么缓冲区他们读书,和一些读者的情况下,要求从管理下一个块,并通知它,当他们不使用一大块了,所以它可能被调离队列

这篇关于我怎么能分裂(复制)在.NET中的流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆