本文整理汇总了PHP中bzread函数的典型用法代码示例。如果您正苦于以下问题:PHP bzread函数的具体用法?PHP bzread怎么用?PHP bzread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bzread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例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: _read
/**
* {@inheritdoc}
*/
protected function _read($length)
{
$data = bzread($this->_fileHandler, $length);
if (false === $data) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Failed to read data from %1', [$this->_filePath]));
}
return $data;
}
示例4: _read
/**
* Read data from bz archive
*
* @throws Mage_Exception
* @param int $length
* @return string
*/
protected function _read($length)
{
$data = bzread($this->_fileHandler, $length);
if (false === $data) {
throw new Mage_Exception('Failed to read data from ' . $this->_filePath);
}
return $data;
}
示例5: bzfile
function bzfile($file)
{
$bz = bzopen($file, "r");
$str = "";
while (!feof($bz)) {
$str = $str . bzread($bz, 8192);
bzclose($bz);
}
return $str;
}
示例6: 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;
}
示例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: 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"));
}
示例9: 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;
}
示例10: 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;
}
示例11: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var RenaApp $app */
$app = RenaApp::getInstance();
// Setup the url and cache path
$url = "https://www.fuzzwork.co.uk/dump/";
$cache = __DIR__ . "/../../cache/update";
// Create the cache dir if it doesn't exist
if (!file_exists($cache)) {
mkdir($cache);
}
// Fetch the md5
$md5file = "mysql-latest.tar.bz2.md5";
$md5 = explode(" ", $app->cURL->getData($url . $md5file, 0))[0];
$lastSeenMD5 = $app->Storage->get("ccpdataMD5");
if ($lastSeenMD5 !== $md5 || !$input->getOption("force") === false) {
$output->writeln("Updating to latest CCP data dump");
$dbFiles = array("dgmAttributeCategories", "dgmAttributeTypes", "dgmEffects", "dgmTypeAttributes", "dgmTypeEffects", "invFlags", "invGroups", "invTypes", "mapDenormalize", "mapRegions", "mapSolarSystems", "mapConstellations");
$type = ".sql.bz2";
foreach ($dbFiles as $file) {
$output->writeln("Updating {$file}");
$dataURL = $url . "latest/" . $file . $type;
try {
file_put_contents("{$cache}/{$file}{$type}", $app->cURL->getData($dataURL, 0));
$sqlData = bzopen("{$cache}/{$file}{$type}", "r");
// Open the BZip data
// Read the BZip data and append it to data
$data = "";
while (!feof($sqlData)) {
$data .= bzread($sqlData, 4096);
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
// Since rena uses tokuDB, we'll replace InnoDB with TokuDB here, just because we can..
$data = str_replace("ENGINE=InnoDB", "ENGINE=TokuDB", $data);
$dataParts = explode(";\n", $data);
foreach ($dataParts as $qry) {
$query = $qry . ";";
$app->Db->execute($query);
}
// Remove the stored BZip file from the drive - no need to store it..
unlink("{$cache}/{$file}.sql.bz2");
}
$app->Storage->set("ccpdataMD5", $md5);
}
}
示例12: load_bz
static function load_bz($file_name)
{
global $wgOfflineWikiPath;
$path = "{$wgOfflineWikiPath}/{$file_name}";
if (strlen($file_name) < 1) {
return null;
}
#strange that bzopen doesn't choke on dir.
$bz = bzopen($path, "r");
if (!$bz) {
return null;
}
$out = "";
while ($bz && !feof($bz)) {
$out .= bzread($bz, 8192);
}
bzclose($bz);
return $out;
}
示例13: unpack
/**
* Unpack file by BZIP2 compressor.
*
* @param string $source
* @param string $destination
* @return string
*/
public function unpack($source, $destination)
{
$data = '';
$bzPointer = bzopen($source, 'r');
if (empty($bzPointer)) {
throw new Exception('Can\'t open BZ archive : ' . $source);
}
while (!feof($bzPointer)) {
$data .= bzread($bzPointer, 131072);
}
bzclose($bzPointer);
if (is_dir($destination)) {
$file = $this->getFilename($source);
$destination = $destination . $file;
}
echo $destination;
$this->_writeFile($destination, $data);
return $destination;
}
示例14: uncompress
/**
* Décompression du contenu. Si path est donné les fichiers sont décompressés dans le répertoire en question,
* sinon, ils sont retournés "en mémoire".
*
* @param filename, path where uncompress
* @return buffer uncompressed or boolean for save success if path given
*/
public function uncompress($filename, $path = null)
{
if (!($bz = bzopen($filename, "r"))) {
return null;
}
$decompressed_file = '';
while (!feof($bz)) {
$decompressed_file .= bzread($bz, 4096);
}
bzclose($bz);
if ($path) {
if ($fp = fopen($path, 'w')) {
fwrite($fp, $decompressed_file, strlen($decompressed_file));
fclose($fp);
return true;
}
return false;
}
return $decompressed_file;
}
示例15: getFile
function getFile($full_filename)
{
$extension = pathinfo($full_filename, PATHINFO_EXTENSION);
if ($extension == "bz2")
{
$bz = bzopen($full_filename, "r");
while (!feof($bz))
$data .= bzread($bz, 4096);
bzclose($bz);
}
else
{
$bz = fopen($full_filename, "r");
while (!feof($bz))
$data .= fread($bz, 4096);
fclose($bz);
}
return $data;
}