我有一个不可搜索的只读 System.IO.Stream 实现(并且它的 Position 总是返回 0).我需要将它发送给在流上执行一些 Seek 操作(也就是设置位置)的使用者.这不是一个巨大的搜索 - 例如从当前位置 +/- 100.是否有现有的 Stream 包装器可以为流添加缓冲能力以进行简单的 Seek 操作?
I have a readonly System.IO.Stream implementation that is not seekable (and its Position always returns 0). I need to send it to a consumer that does some Seek operations (aka, sets the Position) on the stream. It's not a huge seek -- say +/- 100 from the current position. Is there an existing Stream wrapper that will add a buffering ability to the stream for simple Seek operations?
更新:我应该补充一点,我的消费者是 NAudio Mp3FileReader.我真的只需要一种方法来播放(缓慢且无限期地)流式 MP3.我认为这是 NAudio 希望能够随意寻找他们的数据源的错误.
Update: I should add that my consumer is the NAudio Mp3FileReader. I really just need a way to play a (slowly and indefinitely) streaming MP3. I think it's a bug that NAudio expects to be able to seek their data source at will.
向前查找很容易(只需阅读),但如果不进行缓冲,则无法向后查找.也许只是:
Seeking forwards is easy enough (just read), but you can't seek backwards without buffering. Maybe just:
using(var ms = new MemoryStream()) {
otherStream.CopyTo(ms);
ms.Position = 0;
// now work with ms
}
然而,这仅适用于小到中等的流(不是 GB),已知会结束(哪些流不需要这样做).如果您需要更大的流,可以使用 FileStream 到临时文件,但 IO 密集程度要高得多.
This, however, is only suitable for small-to-moderate streams (not GB), that are known to end (which streams are not requires to do). If you need a larger stream, a FileStream to a temp-file would work, but is significantly more IO-intensive.
这篇关于流包装器使流可查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
LINQ to SQL:如何在不检索整个实体的情况下更新唯LINQ to SQL: how to update the only field without retrieving whole entity(LINQ to SQL:如何在不检索整个实体的情况下更新唯一字段)
string1 >= string2 未在 Linq to SQL 中实现,有什string1 gt;= string2 not implemented in Linq to SQL, any workaround?(string1 gt;= string2 未在 Linq to SQL 中实现,有什么解决方法吗?)
如何在条件下使用 RemoveAll 删除列表中的多个项目How to Remove multiple items in List using RemoveAll on condition?(如何在条件下使用 RemoveAll 删除列表中的多个项目?)
转换表达式树Convert Expression trees(转换表达式树)
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“ClientCannot insert explicit value for identity column in table #39;ClientDetails#39; when IDENTITY_INSERT is set to OFF(当 IDENTITY_INSERT 设置为 OFF 时,
Linq 独特的 &最大限度Linq distinct amp; max(Linq 独特的 amp;最大限度)