diff options
author | Patrick Brown <ptbrown@whoopdedo.org> | 2015-05-06 23:31:39 -0400 |
---|---|---|
committer | Patrick Brown <ptbrown@whoopdedo.org> | 2015-05-06 23:31:39 -0400 |
commit | cfb71e37ca8859c4ad9a1db73de0a293ffc7a902 (patch) | |
tree | 96ee25434bc1950edb0ee0286647fac6bea6403d /inc | |
parent | 369075828e13e37a65a2f8062a74e89f98dd3fac (diff) | |
download | rpg-cfb71e37ca8859c4ad9a1db73de0a293ffc7a902.tar.gz rpg-cfb71e37ca8859c4ad9a1db73de0a293ffc7a902.tar.bz2 |
Deleting lines works with BZ2 files.
Diffstat (limited to 'inc')
-rw-r--r-- | inc/io.php | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/inc/io.php b/inc/io.php index 8846b7e56..b8a77b730 100644 --- a/inc/io.php +++ b/inc/io.php @@ -127,22 +127,36 @@ function io_readFile($file,$clean=true){ * @author Andreas Gohr <andi@splitbrain.org> * * @param string $file filename - * @return string|bool content or false on error + * @param bool $array return array of lines + * @return string|array|bool content or false on error */ -function bzfile($file){ +function bzfile($file, $array=false) { $bz = bzopen($file,"r"); if($bz === false) return false; + if($array) $lines = array(); $str = ''; - while (!feof($bz)){ + while (!feof($bz)) { //8192 seems to be the maximum buffersize? $buffer = bzread($bz,8192); if(($buffer === false) || (bzerrno($bz) !== 0)) { return false; } $str = $str . $buffer; + if($array) { + $pos = strpos($str, "\n"); + while($pos !== false) { + $lines[] = substr($str, 0, $pos+1); + $str = substr($str, $pos+1); + $pos = strpos($str, "\n"); + } + } } bzclose($bz); + if($array) { + if($str !== '') $lines[] = $str; + return $lines; + } return $str; } @@ -280,6 +294,8 @@ function io_deleteFromFile($file,$badline,$regex=false){ // load into array if(substr($file,-3) == '.gz'){ $lines = gzfile($file); + }else if(substr($file,-4) == '.bz2'){ + $lines = bzfile($file, true); }else{ $lines = file($file); } @@ -306,6 +322,15 @@ function io_deleteFromFile($file,$badline,$regex=false){ } gzwrite($fh, $content); gzclose($fh); + }else if(substr($file,-4) == '.bz2'){ + $fh = @bzopen($file,'w'); + if(!$fh){ + msg("Removing content from $file failed",-1); + io_unlock($file); + return false; + } + bzwrite($fh, $content); + bzclose($fh); }else{ $fh = @fopen($file,'wb'); if(!$fh){ |