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 | 4 Comments »

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

  1. รับซื้อแบรนด์เนม Says:
    November 9th, 2024 at 03:39

    … [Trackback]

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

  2. กายภาพ Says:
    November 18th, 2024 at 22:45

    … [Trackback]

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

  3. gambia Says:
    December 5th, 2024 at 16:36

    … [Trackback]

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

  4. mkx gummies sativa or indica Says:
    December 17th, 2024 at 17:10

    … [Trackback]

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

Comments