cgwebprojects
cgwebprojects

Reputation: 3482

GZIP decode file with php, have it working just trying to get rid of errors outputted by E_ALL

I have this function for decoding gzipped files,

// GZIP DECODE
function gzipDecode($d) {
    $f = ord(substr($d, 3, 1));
    $h = 10;
    $e = 0;
    if($f&4) {
        $e = unpack('v', substr($d, 10, 2));
        $e = $e[1];
        $h += 2 + $e;
    }
    if($f&8) {
        $h = @strpos($d, chr(0), $h) + 1;
    }
    if($f&16) {
        $h = strpos($d, chr(0), $h) + 1;
    }
    if($f&2) {
        $h += 2;
    }
    $u = @gzinflate(substr($d, $h));
    if($u == false) {
        $u = $d;
    }
    return $u;
}

It works as expected but I turned on error reporting and I get these two errors

Warning: strpos(): Offset not contained in string

AND

Warning: gzinflate(): data error

These warnings refer to the bits of code above that have been error supressed, have any idea on how I can fix them?

Thanks

Upvotes: 1

Views: 790

Answers (1)

Mark Adler
Mark Adler

Reputation: 112627

Have you tried simply using gzdecode()?

Your header decoding looks correct. You should check that your gzip stream is really starting where you think it does by checking the first three bytes for 0x1f, 0x8b, 8.

Upvotes: 0

Related Questions