A
A
aymeshkov2010-12-23 20:00:07
C++ / C#
aymeshkov, 2010-12-23 20:00:07

c# GzipStream decompress stream only if it is really packed

In general, the question is not obvious at first glance.

What we have: We have

an inputStream .
We know that it is possibly gzipped. And perhaps not.

What is required:

It is required to read this stream, decompressing if necessary.
If you just wrap it in a GzipStream, it will crash with the error "The magic number in GZip header is not correct".

What's the catch:

You can't just subtract the stream into byte[], and then play with this array, as there are severe speed limits.
Does anyone have any suggestions how to do this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
eternals, 2010-12-23
@aymeshkov

Offhand: make a wrapper stream that will check magic and then pass or not pass through GZipStream.

E
eternals, 2010-12-23
@eternals

RFC 1952

K
kekekeks, 2010-12-24
@kekekeks

Etssamoe, the bottom line is that even if the magic matches, there is a chance that there is never a gzip inside.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question