本文整理汇总了PHP中bzopen函数的典型用法代码示例。如果您正苦于以下问题:PHP bzopen函数的具体用法?PHP bzopen怎么用?PHP bzopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bzopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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("не удалось открыть файл");
}
}
示例2: _open
/**
* Open bz archive file
*
* @throws Mage_Exception
* @param string $mode
*/
protected function _open($mode)
{
$this->_fileHandler = @bzopen($this->_filePath, $mode);
if (false === $this->_fileHandler) {
throw new Mage_Exception('Failed to open file ' . $this->_filePath);
}
}
示例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: dumpHeaders
function dumpHeaders($identifier, $multi_table = false)
{
if ($_POST["output"] == "bz2") {
$this->filename = tempnam("", "bz2");
$this->fp = bzopen($this->filename, 'w');
header("Content-Type: application/x-bzip");
ob_start(array($this, '_bz2'), 1000000.0);
}
}
示例5: 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;
}
示例6: bzfile
function bzfile($file)
{
$bz = bzopen($file, "r");
$str = "";
while (!feof($bz)) {
$str = $str . bzread($bz, 8192);
bzclose($bz);
}
return $str;
}
示例7: newFile
/**
* @see File_Archive_Writer::newFile()
*
* Check that one single file is written in the BZip2 archive
*/
function newFile($filename, $stat = array(), $mime = "application/octet-stream")
{
if ($this->nbFiles > 1) {
return PEAR::raiseError("A Bzip2 archive can only contain one single file." . "Use Tbz archive to be able to write several files");
}
$this->nbFiles++;
$this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far');
$this->bzfile = bzopen($this->tmpName, 'w' . $this->compressionLevel);
return true;
}
示例8: _open
/**
* {@inheritdoc}
* @throws \RuntimeException
*/
protected function _open($mode)
{
if (!extension_loaded('bz2')) {
throw new \RuntimeException('PHP extension bz2 is required.');
}
$this->_fileHandler = bzopen($this->_filePath, $mode);
if (false === $this->_fileHandler) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Failed to open file %1', [$this->_filePath]));
}
}
示例9: __construct
public function __construct($file)
{
parent::__construct($file, FileDecoder::DECODER_BZIP2);
if (!extension_loaded("bz2")) {
throw new Exception(Log::err("Missing extension 'bz2' for bzip2 decoding"));
}
$this->tResource = bzopen($file, "r");
if ($this->tResource === false) {
throw new Exception(Log::err("Cannot open file '{$file}' for reading"));
}
}
示例10: 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);
}
示例11: 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);
}
示例12: 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"));
}
示例13: stream_open
public function stream_open($path, $mode, $options, &$opened_path)
{
if (!function_exists('bzopen')) {
return false;
}
$resource = bzopen($path, $mode);
if (!$resource) {
return false;
}
$this->_path = $path;
$this->_mode = $mode;
$this->_resource = $resource;
}
示例14: 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;
}
示例15: 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;
}