{"id":16,"date":"2008-08-09T16:55:23","date_gmt":"2008-08-09T20:55:23","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=16"},"modified":"2010-07-21T20:18:45","modified_gmt":"2010-07-22T01:18:45","slug":"simple-way-to-read-bzip2-compressed-files-in-php","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2008\/08\/09\/simple-way-to-read-bzip2-compressed-files-in-php\/","title":{"rendered":"Simple way to read bzip2 compressed files in PHP"},"content":{"rendered":"<p>If you are looking for a way to read quick way to read a compressed bzip2 file&#8217;s contents, look no further. We have made a function that works similar to the way <a href=\"http:\/\/php.net\/file_get_contents\">file_get_contents<\/a> works.<\/p>\n<p>The code is released under the GPL v2 or later license.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\/**\r\n* Reads an uncompressed file from a bzip2 file\r\n*\r\n* @function file_bzip2_contents\r\n* @author Compdigitec - http:\/\/www.compdigitec.com\/\r\n* @copyright (C)Copyright 2008 Compdigitec. All rights reserved.\r\n* @license http:\/\/www.gnu.org\/licenses\/gpl-2.0.txt\r\n* @param string $filename The filename of the bz2 compressed file\r\n* @param resource $res An existing resource opened by bzopen\r\n* @return string The contents of the bzip2 file\r\n*\/\r\n\r\nfunction file_bzip2_contents($filename,$res = null) {\r\n$file = strval($filename); \/\/ Avoid bad input\r\nif($res === null) {\r\n$res = bzopen($filename,'r');\r\n$a = '1qza';\r\n};\r\n$contents = bzread($res);\r\nif($a == &quot;1qza&quot;) {\r\nbzclose($res);\r\n}\r\nreturn $contents;\r\n}\r\n\r\n?&gt;\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>If you are looking for a way to read quick way to read a compressed bzip2 file&#8217;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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[38,53,864,569],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/16"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}