Groups | Blog | Home
all groups > dotnet framework > february 2006 >

dotnet framework : GZipStream Decompress always reads 4K minimum...!


Bob
2/2/2006 5:30:53 PM
I have a network stream of data I am reading, of which, a section is
compressed and can be decompressed using GZipStream's decompression. This
part works great, however, even if the part being decompressed is 1K,
GZipStream /always/ reads 4K minimum off my primary stream. Using .NET
Reflector I can see they have a 4K buffer internally and always read in
chunks of 4K.

Basically, I have to force GZipStream to only read what is compressed, and
no more. This should be possible because I am reading fixed sized
structures out of GZipStream and upon the last structure I should begin
reading uncompressed data again.

Do I have any options here?

Thanks

Bob
2/2/2006 5:59:23 PM
Thanks for responding... but thats the problem, I don't know the exact size
of the compressed data. I just know "when to stop reading compressed data."
Even if I add an additional stream between the network stream and
GZipStream, I don't know where to position the uncompressed data (I don't
know how much compressed data GZipStream read, I only know how much
uncompressed data was read).


"David Browne" <davidbaxterbrowne no potted meat@hotmail.com> wrote in
message news:%23f1Z2OGKGHA.2828@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

David Browne
2/2/2006 7:46:47 PM

[quoted text, click to view]


Sure. Just read off your compressed data into a fixed-size buffer and feed
that to the GZipStream by wrapping it in a MemoryStream.

byte[] buf = new byte[1024];
//read fixed-length compressed data into buf
GZipStream gs = new GZipStream(new MemoryStream(buf));

David

Lloyd Dupont
2/3/2006 12:00:00 AM
You might try:
http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
[quoted text, click to view]

Lloyd Dupont
2/3/2006 12:00:00 AM
You could also write the size of the compressed data first.

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
[quoted text, click to view]

Jon Skeet [C# MVP]
2/3/2006 12:00:00 AM
[quoted text, click to view]

So you've got some amount of compressed data and then some other data,
with no idea beforehand how much compressed data there was? That's a
really bad protocol design, unfortunately - you're likely to have
difficulty in decoding it.

Do you control the protocol, or does it "belong" to someone else?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
AddThis Social Bookmark Button