Can I rely on the first few bytes of data compressed using the System.IO.Compression.DeflateStream in .NET always being the same?
These bytes seem to always be the 1st bytes: 237, 189, 7, 96, 28, 73, 150, 37, 38, 47 , ...
I'm assuming this is some kind of header, I'd like to assume that this header is fixed and isn't going to change.
Has anyone got any extra info about this?
Background info (The reason I want to know this info is...)
I have a load of data in a database table that could do with being made smaller. I've decided I'm going to start compressing the data and not going to bother compressing the existing data. When the data gets into my .NET code the data is a String.
I'd like to be able to look at the 1st few bytes of the string and see if it has been compressed, if it has then I need to de-compress it.
I was originally thinking I could convert the string to bytes and just try de-compressing the data. Then if an exception happens, I could just assume it wasn't compressed. But I think checking the header bytes would give me much better performance.
Many thanks, Mike G
To be safe (unless this is documented somewhere), stick your own magic header at the front. A GUID is a good choice for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With