在.NET良好的zlib执行?良好、NET、zlib

2023-09-03 03:39:09 作者:女神快到碗里来

我建立,需要能够从正常的网络流量切换到 zlib的的玉米pressed流中的网络应用,中游。我对此事的想法涉及布尔开关上时,会导致网络code通过,我可以养活的IEnumerable℃的类传递所有的数据;字节> 成,然后拉出DECOM pressed流,传递一个到已有的协议分析code。

I'm building an network application that needs to be able to switch from normal network traffic to a zlib compressed stream, mid stream. My thoughts on the matter involve boolean switch that when on will cause the network code to pass all the data through a class that I can feed IEnumerable<byte> into, and then pull out the decompressed stream, passing that on to the already existing protocol parsing code.

东西:

ZLib.NET - 这似乎有点...... Ecclectic,不完全是我想要的。仍然有一份体面的开始蓄客,虽然。 (Jon飞碟双向的评论在这里很难激发我满意。) SharpZipLib - 这似乎并不支持zlib的呢?任何人都可以证实或否认这一点? ZLib.NET - It seems a little... Ecclectic, and not quite what I want. Would still make a decent start to build off though. (Jon Skeet's comments here hardly inspire me either.) SharpZipLib - This doesn't seem to support zlib at all? Can anyone confirm or deny this?

我会非常preFER和所有被管理的解决方案,但让我们在它...是否有这个库中的任何其他实现赫然出现在.NET中,这可能是更适合我想做的事情,或者我应该采取ZLib.NET和蓄客,作为一个开始?

I would very much prefer and all managed solution, but let's have at it... are there any other implementations of this library out there in .NET, that might be better suited to what I want to do, or should I take ZLib.NET and build off that as a start?

PS:

乔恩的要求更多的细节,所以在这儿呢。

Jon's asked for more detail, so here it is.

我想实现 MCCP 2 。这涉及到正在发送的网络流的信号,并且该信号后一切一个zlib的玉米pressed数据流。有链接,究竟是什么意思,在上面的链接。总之,要清楚,我在此recieving端(客户端,而不是服务器),我有一堆宣读了已经在网络流数据,并切换将在这中间(在所有的情形产生ATLEAST),因此任何解决方案需要能够有供入一些额外的数据,它需要之前通过的NetworkStream(或I手动送入的数据的剩余部分)。

I'm trying to implement MCCP 2. This involves a signal being sent in the network stream, and everything after this signal is a zlib compressed data stream. There's links to exactly what they mean by that in the above link. Anyway, to be clear, I'm on the recieving end of this (client, not server), and I have a bunch of data read out of the network stream already, and the toggle will be in the middle of this (in all likelyhood atleast), so any solution needs to be able to have some extra data fed into it, before it takes over the NetworkStream (or I manually feed in the rest of the data).

推荐答案

SharpZipLib不支持的ZLib。看看此FAQ条目。

SharpZipLib does support ZLib. Look at this FAQ entry.

此外,有你检查System.IO.Com pression命名空间是否支持你需要什么?

Additionally, have you checked whether the System.IO.Compression namespace supports what you need?

我不会用一个的IEnumerable&LT;字节&GT; 虽然 - 流设计为链接在一起

I wouldn't use an IEnumerable<byte> though - streams are designed to be chained together.

编辑:好吧......这听起来像您需要支持缓冲的流,但比 BufferedStream 提供了更多的控制。你需要倒带流如果你看到了DE​​COM pression拨动,然后创建它的顶部一个GZipStream。您的缓冲区将需要至少一样大,你最大的调用阅读(),所以你总是可以有足够的缓冲快退。

Okay... it sounds like you need a stream which supports buffering, but with more control than BufferedStream provides. You'd need to "rewind" the stream if you saw the decompression toggle, and then create a GZipStream on top of it. Your buffer would need to be at least as big as your biggest call to Read() so that you could always have enough buffer to rewind.