Home All Groups Group Topic Archive Search About

Is MemoryStream compressed?

Author
3 Jul 2009 8:04 PM
bamelyan
Is there a way to determine wether a MemoryStream is compressed, i.e. needs
to be decompressed with GZipStream?

Author
3 Jul 2009 8:45 PM
Arne Vajhøj
bamelyan wrote:
> Is there a way to determine wether a MemoryStream is compressed, i.e. needs
> to be decompressed with GZipStream?  

Not really.

Bytes are just bytes.

If the first 3 bytes are 0x1f 0x8b 0x08 then there is a decent chance
it is gzipped.

Arne
Are all your drivers up to date? click for free checkup

Author
3 Jul 2009 9:31 PM
bamelyan
thanks for quick response.  what's the expected behavior of GZipStream if i
try to decompress a stream that is not compressed?

Show quoteHide quote
"Arne Vajhøj" wrote:

> bamelyan wrote:
> > Is there a way to determine wether a MemoryStream is compressed, i.e. needs
> > to be decompressed with GZipStream?  
>
> Not really.
>
> Bytes are just bytes.
>
> If the first 3 bytes are 0x1f 0x8b 0x08 then there is a decent chance
> it is gzipped.
>
> Arne
>
Author
3 Jul 2009 11:02 PM
Arne Vajhøj
bamelyan wrote:
> "Arne Vajhøj" wrote:
>> bamelyan wrote:
>>> Is there a way to determine wether a MemoryStream is compressed, i.e. needs
>>> to be decompressed with GZipStream?  
>> Not really.
>>
>> Bytes are just bytes.
>>
>> If the first 3 bytes are 0x1f 0x8b 0x08 then there is a decent chance
>> it is gzipped.
> thanks for quick response.  what's the expected behavior of
GZipStream if i
> try to decompress a stream that is not compressed?

I think one of two will happen:
* if the data just happens to be a valid GZIP format then you
   will get absolute garbage
* else (and that is by far the most likely) then you will
   get a InvalidDataException

Arne

Bookmark and Share