Home All Groups Group Topic Archive Search About

GZipStream Decompress always reads 4K minimum...!

Author
3 Feb 2006 1:30 AM
Bob
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

Author
3 Feb 2006 1:46 AM
David Browne
Show quote
"Bob" <nob***@nowhere.com> wrote in message
news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl...
>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?


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
Author
3 Feb 2006 1:59 AM
Bob
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).


Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:%23f1Z2OGKGHA.2828@TK2MSFTNGP12.phx.gbl...
>
> "Bob" <nob***@nowhere.com> wrote in message
> news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl...
>>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?
>
>
> 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
>
Author
3 Feb 2006 2:23 AM
Lloyd Dupont
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>
Show quote
"Bob" <nob***@nowhere.com> wrote in message
news:ew3I4VGKGHA.1532@TK2MSFTNGP12.phx.gbl...
> 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 m***@hotmail.com> wrote in
> message news:%23f1Z2OGKGHA.2828@TK2MSFTNGP12.phx.gbl...
>>
>> "Bob" <nob***@nowhere.com> wrote in message
>> news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl...
>>>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?
>>
>>
>> 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
>>
>
>
Author
3 Feb 2006 7:24 AM
Jon Skeet [C# MVP]
Bob <nob***@nowhere.com> wrote:
> 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).

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 - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
3 Feb 2006 2:23 AM
Lloyd Dupont
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>
Show quote
"Bob" <nob***@nowhere.com> wrote in message
news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl...
>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
>

AddThis Social Bookmark Button