Compdigitec Labs

« | Home | »

Simple way to read bzip2 compressed files in PHP

By admin | August 9, 2008

If you are looking for a way to read quick way to read a compressed bzip2 file’s contents, look no further. We have made a function that works similar to the way file_get_contents works.

The code is released under the GPL v2 or later license.

<?php
/**
* Reads an uncompressed file from a bzip2 file
*
* @function file_bzip2_contents
* @author Compdigitec - http://www.compdigitec.com/
* @copyright (C)Copyright 2008 Compdigitec. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt
* @param string $filename The filename of the bz2 compressed file
* @param resource $res An existing resource opened by bzopen
* @return string The contents of the bzip2 file
*/

function file_bzip2_contents($filename,$res = null) {
$file = strval($filename); // Avoid bad input
if($res === null) {
$res = bzopen($filename,'r');
$a = '1qza';
};
$contents = bzread($res);
if($a == "1qza") {
bzclose($res);
}
return $contents;
}

?>

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: PHP | 2 Comments »

2 Responses to “Simple way to read bzip2 compressed files in PHP”

  1. ks quik 2000 Says:
    March 20th, 2024 at 21:58

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2008/08/09/simple-way-to-read-bzip2-compressed-files-in-php/ […]

  2. pod Says:
    April 19th, 2024 at 19:51

    … [Trackback]

    […] Find More on that Topic: compdigitec.com/labs/2008/08/09/simple-way-to-read-bzip2-compressed-files-in-php/ […]

Comments