本文整理汇总了PHP中bzclose函数的典型用法代码示例。如果您正苦于以下问题:PHP bzclose函数的具体用法?PHP bzclose怎么用?PHP bzclose使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bzclose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
public function extract($archive="", $outputDir = "")
{
$gzh = gzopen($archive, 'r') or die("Could not open $archive");
if(!is_dir($outputDir))
{
mkdir($outputDir, 0700, true) or die("Could not create a $outputDir directory");
}
$_archive = str_ireplace('.tgz', '.gz', $archive);
$tar_path = basename($_archive, '.gz');
$lchar = substr($outputDir, -1);
if('/' == $lchar OR '\\' == $lchar)
{
$tar_path = $outputDir.$tar_path;
} else {
$tar_path = $outputDir."/".$tar_path;
}
$fh = fopen($tar_path, "w");
while(!feof($gzh))
{
$cstr = gzread($gzh, 4096);
fwrite($fh, $cstr);
}
bzclose($gzh);
fclose($fh);
$this->tarHandler->extract($tar_path, $outputDir);
echo "<font color=\"green\">Sucessfull!</font>";
}
示例2: getLines
protected function getLines()
{
$handle = bzopen($this->file, "r");
if ($handle) {
$decompressedData = '';
while (true) {
do {
if (feof($handle)) {
bzclose($handle);
return;
}
$decompressedData .= bzread($handle, 8192);
$key = strpos($decompressedData, "\n");
} while ($key === false);
do {
$line = substr($decompressedData, 0, $key + 1);
$decompressedData = substr_replace($decompressedData, '', 0, $key + 1);
(yield $line);
$key = strpos($decompressedData, "\n");
} while ($key !== false);
}
} else {
throw new \Exception("не удалось открыть файл");
}
}
示例3: decompress
/**
* Static method to decompress data
*
* @param string $data
* @return mixed
*/
public static function decompress($data)
{
// Decompress the file
if (@file_exists($data)) {
$bz = bzopen($data, 'r');
$uncompressed = '';
// Read the uncompressed data.
while (!feof($bz)) {
$uncompressed .= bzread($bz, 4096);
}
// Close the Bzip2 compressed file and write
// the data to the uncompressed file.
bzclose($bz);
if (stripos($data, '.tbz2') !== false) {
$newFile = str_replace('.tbz2', '.tar', $data);
} else {
if (stripos($data, '.tbz') !== false) {
$newFile = str_replace('.tbz', '.tar', $data);
} else {
$newFile = str_replace('.bz2', '', $data);
}
}
file_put_contents($newFile, $uncompressed);
return $newFile;
// Else, decompress the string
} else {
return bzdecompress($data);
}
}
示例4: read
public function read($file)
{
$open = bzopen($file, 'r');
if (empty($open)) {
throw new FileNotFoundException('Error', 'fileNotFound', $file);
}
$return = bzread($open, 8096);
bzclose($open);
return $return;
}
示例5: bzfile
function bzfile($file)
{
$bz = bzopen($file, "r");
$str = "";
while (!feof($bz)) {
$str = $str . bzread($bz, 8192);
bzclose($bz);
}
return $str;
}
示例6: _bz2
function _bz2($string, $state)
{
bzwrite($this->fp, $string);
if ($state & PHP_OUTPUT_HANDLER_END) {
bzclose($this->fp);
$return = file_get_contents($this->filename);
unlink($this->filename);
return $return;
}
return "";
}
示例7: bunzip
function bunzip($infile, $outfile)
{
$string = null;
$zp = bzopen($infile, "r");
while (!feof($zp)) {
$string .= bzread($zp, 4096);
}
bzclose($zp);
$fp = fopen($outfile, "w");
fwrite($fp, $string, strlen($string));
fclose($fp);
}
示例8: compress
public function compress($fileName)
{
$this->tarHandler->compress($fileName);
$bzh = bzopen($fileName . '.tar.bz2', 'wb');
$th = fopen($fileName . ".tar", 'rb');
while (!feof($th)) {
$ustr = fread($th, 1048576);
bzwrite($bzh, $ustr);
}
bzclose($bzh);
fclose($th);
}
示例9: test_bzerror
function test_bzerror()
{
global $tmpfile;
$f = fopen($tmpfile, "w");
fwrite($f, "this is a test");
fclose($f);
$f = bzopen($tmpfile, "r");
bzread($f);
$ret = bzerror($f);
bzclose($f);
unlink($tmpfile);
VS($ret, array("errno" => -5, "errstr" => "DATA_ERROR_MAGIC"));
}
示例10: extract
/**
* {@inheritdoc}
*/
public function extract($file, $target, Format\FormatInterface $format)
{
$this->checkSupport($format);
$basename = pathinfo($file, PATHINFO_FILENAME);
if (false === $this->isValid($file)) {
throw new Exception\IO\Input\FileCorruptedException($file, Exception\IO\Input\FileCorruptedException::SEVERITY_HIGH);
}
$source = bzopen($file, 'r');
$this->getFilesystem()->mkdir($target);
$destination = fopen($target . DIRECTORY_SEPARATOR . $basename, 'w');
$bytes = stream_copy_to_stream($source, $destination);
bzclose($source);
fclose($destination);
return $bytes > 0;
}
示例11: extractBzip2
function extractBzip2($src, $dest = false)
{
$bz = bzopen($src, "r");
$data = '';
while (!feof($bz)) {
$data .= bzread($bz, 1024 * 1024);
}
bzclose($bz);
if (empty($dest)) {
return $data;
} elseif (file_put_contents($dest, $data)) {
return $dest;
}
return false;
}
示例12: peekLine
public function peekLine()
{
$line = false;
if ($this->tResource !== false) {
if ($this->tLine === false) {
$this->tLine = gzgets($this->tResource, FileDecoder::BUFLEN);
}
if ($this->tLine !== false) {
$line = $this->tLine;
} else {
bzclose($this->tResource);
$this->tResource = false;
}
}
return $line;
}
示例13: read
public function read($file = '', $length = 1024, $type = NULL)
{
if (!is_string($file) || empty($file)) {
return Error::set('Error', 'stringParameter', '1.(file)');
}
if (!is_numeric($length)) {
return Error::set('Error', 'numericParameter', '2.(length)');
}
$open = bzopen($file, 'r');
if (empty($open)) {
return Error::set('Error', 'fileNotFound', $file);
}
$return = bzread($open, $length);
bzclose($open);
return $return;
}
示例14: x
function x()
{
$uncheckedDir = opendir('.');
readdir($uncheckedDir);
$uncheckedDir2 = bzopen('.');
bzclose($uncheckedDir2);
$uncheckedDir3 = fopen('.', 'r+');
fclose($uncheckedDir3);
readdir(opendir('uncheckedDir4'));
readdir2(opendir('uncheckedDir5'));
readdir(opendir2('uncheckedDir6'));
$pspell_new = pspell_new('asdfasdf');
while ($f = pspell_suggest($pspell_new)) {
print "{$f}\n";
}
}
示例15: bzip2
function bzip2($in, $out)
{
if (!file_exists($in) || !is_readable($in)) {
return false;
}
if (!file_exists($out) && !is_writeable(dirname($out)) || file_exists($out) && !is_writable($out)) {
return false;
}
$in_file = fopen($in, "r");
$out_file = bzopen($out, "w");
while (!feof($in_file)) {
$buffer = fgets($in_file, 4096);
bzwrite($out_file, $buffer, 4096);
}
fclose($in_file);
bzclose($out_file);
return true;
}