I wrote the function I was looking for based on the comments in the manual:
/** * @param string $path to gzipped file * @return string */ public function gz_get_contents($path) { // gzread needs the uncompressed file size as a second argument // this might be done by reading the last bytes of the file $handle = fopen($path, "rb"); fseek($handle, -4, SEEK_END); $buf = fread($handle, 4); $unpacked = unpack("V", $buf); $uncompressedSize = end($unpacked); fclose($handle); // read the gzipped content, specifying the exact length $handle = gzopen($path, "rb"); $contents = gzread($handle, $uncompressedSize); gzclose($handle); return $contents; }
source share