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 | 1 Comment »

One Response to “Simple way to read bzip2 compressed files in PHP”

  1. Joy Organics Says:
    August 25th, 2021 at 18:23

    … [Trackback]

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

Comments