That is to say, a test for whether or not I can safely gzinflate the string.
If my compressed data has been tampered with I get a “bad data” warning. I don’t want to suppress the warning which means I either have to trap it, or test that it can be gzinflated. The latter is my preferred solution but I just don’t know how.
Something to fit the code sample below would be perfect:
if(i_can_haz_inflate($data))
{
// go ahead
$source = gzinflate($data);
}
else
{
// bad data
}
Edit: Having specified gz(de|in)flate I’ve come to realize that I’m not actually too bothered about the compression algorithm. Are there any out there that are better suited to checking the integrity prior to a decompression attempt?
gzinflate()returns the original string if it’s not agzdeflate()encoded string.The most obvious check would be:
I don’t think there’s another way to do this.