GZipStream Decompression.

R

Robinson

I'm trying to work out how to decompress a GZipStream. I'm not sure how to
allocate the destination buffer, given that I cannot query the stream to
find out the total decompressed size of the item. A hack here
http://www.geekpedia.com/tutorial191_Unzipping-compressed-files-using-GZipStream.html
shows that you can get the last 4 bytes of the stream and convert it into an
integer "size". But this doesn't seem right to me. I could also allocate
one huge buffer, given I know my items won't be greater than 1mb in size
(for now), but this doesn't seem right either. The MSDN documentation
example shows that of course the decompress buffer is the same size as the
original compress buffer, because it uses the information from the original
file size to allocate it.

Is there a generic solution that might work using a memory stream?

Thanks
 
R

Robinson

Robinson said:
I'm trying to work out how to decompress a GZipStream. I'm not sure how
to allocate the destination buffer, given that I cannot query the stream
to find out the total decompressed size of the item. A hack here
http://www.geekpedia.com/tutorial191_Unzipping-compressed-files-using-GZipStream.html
shows that you can get the last 4 bytes of the stream and convert it into
an integer "size". But this doesn't seem right to me. I could also
allocate one huge buffer, given I know my items won't be greater than 1mb
in size (for now), but this doesn't seem right either. The MSDN
documentation example shows that of course the decompress buffer is the
same size as the original compress buffer, because it uses the information
from the original file size to allocate it.

Is there a generic solution that might work using a memory stream?

I solved it by writing my own header (an int32) specifying the size of the
decompressed blob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top