创建 shim 流

发布于 2024-09-02 12:39:31 字数 725 浏览 5 评论 0原文

我正在使用的解压缩 API 具有以下 API:

Decode(Stream inStream,Stream outStream)

我想围绕该 API 创建一个包装器,以便我可以创建自己的 Stream 类来提供解码的数据。

Stream decodedStream=new BlaDecodeStream(inStream);

这样我就可以使用该流作为 XmlReader 构造函数的参数,就像使用 System.IO.Compression.GZipStream 一样。据我所知,唯一的其他选项是将 outStream 流设置为 MemoryStream 或 FileStream 并进行两跳。我正在处理的文件非常大,因此这两个选项都不是特别有吸引力。

在我重新发明轮子之前,是否有任何我可以借鉴的现有技术,或者 BCL 中我可能错过的东西? CircularStream 实现这里会提供一些帮助,但我'我真的在寻找类似的东西,当流的内部缓冲区在读取时为“空”时会阻塞(而不是溢出/欠载),而在写入时内部缓冲区已满时会阻塞。

通过这种方式,它可以用作参数 outStream 并且同时(即从另一个线程)可以由 XmlReader 读取。

A decompression API that I am using has the following API:

Decode(Stream inStream,Stream outStream)

I'd like to create a wrapper around this API, such that I can create my own Stream class which offers up the decoded data.

Stream decodedStream=new BlaDecodeStream(inStream);

So that I can than use this stream as a parameter to the XmlReader constructor in the same way one might use the System.IO.Compression.GZipStream. As far as I can tell, the only other option is set outStream stream to a MemoryStream or to a FileStream and go in two hops. The files I am dealing with are enormous, so neither of these options are particularly attractive.

Before I go reinventing the wheel, is there any prior art that I might be able to draw from, or something in the BCL I might have missed? The CircularStream implementation here would go some of the way to helping, but I'm really looking for something similar that would block (as opposed to over/underrun) when the Stream's internal buffer is 'empty' when reading from it and block when the internal buffer is full when writing to it.

In this way it could serve as parameter outStream and simultaneously (i.e. from another thread) could be read from by the XmlReader.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-09-09 12:39:31

我询问了阻塞流阅读器不久前。我实施了其中一项建议,效果很好。

I asked about a blocking stream reader a while ago. I implemented one of the suggestions and it works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文