How to determine if an array of bytes has been compressed?

Can I rely on the first few bytes of data compressed using System.IO.Compression.DeflateStream in .NET to always be the same?

These bytes always seem to be the 1st byte: 237, 189, 7, 96, 28, 73, 150, 37, 38, 47, ...

I assume that this is some kind of heading, I would like to assume that this heading is corrected and will not change.

Does anyone have more info on this?

Background information (the reason I want to know this information is ...)

I have data loading in a database table, which can be reduced. I decided that I would start compressing the data and was not going to compress the existing data. When the data gets into my .NET code, the data is a string.

I would like to look at the first few bytes of the string and see if it was compressed, if necessary, I need to compress it.

I initially thought that I could convert the string to bytes and just try to remove the data compression. Then, if an exception occurs, I can simply assume that it was not compressed. But I think that checking byte headers will give me much better performance.

Thanks a lot, Mike G

+5
source share
2 answers

To be safe (unless it is documented somewhere), hold your own magic caption in front. A GUID is a good choice for this.

+1
source

.NET 4.0 GZipStream, . , .NET for - :

System.IO.Compression .NET 4. DeflateStream GZipStream .

0

All Articles