本文整理汇总了PHP中bzdecompress函数的典型用法代码示例。如果您正苦于以下问题:PHP bzdecompress函数的具体用法?PHP bzdecompress怎么用?PHP bzdecompress使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bzdecompress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decrypt
/**
* Decode a string from the values that have been generated
*
* @param text string The string that has been encoded
*
* @return string
*/
public static function decrypt($text)
{
$config = Config::settings('encrypt');
$base64key = $config['key'];
$base64ivector = $config['iv'];
return bzdecompress(trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, base64_decode($base64key), base64_decode($text), MCRYPT_MODE_CBC, base64_decode($base64ivector))));
}
示例2: 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);
}
}
示例3: decompress
/**
* Decompress the given value with the specific compression
*
* @param String $sValue
*
* @return String
*
* @throws Exception
*/
public function decompress($sValue)
{
if (!is_string($sValue)) {
throw new Exception('Invalid first argument, must be a string');
}
return bzdecompress($sValue);
}
示例4: testEncode
public function testEncode()
{
$testString = 'a string to be compressed';
$result = $this->encoder->encode($testString);
$uncompressedResult = bzdecompress($result);
$this->assertSame($testString, $uncompressedResult);
}
示例5: recover
function recover($code)
{
if (!$this->getAuthUser()) {
$this->jerr("invalid");
}
// fixme!!!!
$fn = $this->rootDir . '/Pman/' . $code . '.js';
list($app, $mod) = explode('/', $code);
if (!file_exists($fn)) {
$this->jerr("file does not exist.:" . $fn);
}
$data = file_get_contents($fn);
preg_match("#/*\n--SOURCE--\n([^\\*]+)#m", $data, $matches);
// echo "<PRE>";print_R($matches);
$base = $matches[1];
$str = bzdecompress(base64_decode($base));
$js = json_decode($str);
//echo "<PRE>";print_R($str);
$b = DB_DataObject::factory('builder');
$b->app = $app;
$b->module = $mod;
$b->btype = 'FORM';
$b->name = $js->name;
if (!$b->find(true)) {
$b->insert();
}
echo "<PRE>" . htmlspecialchars(print_r($b, true));
$b->json = $str;
$b->update();
$this->jok("DONE");
exit;
}
示例6: decompress
/**
* {@inheritdoc}
*/
public function decompress($data, $length)
{
$output = @bzdecompress(substr($data, 0, $length));
if (!is_string($output)) {
throw new InvalidInputDataException('The decompression input data is invalid.', $output);
}
return $output;
}
示例7: ReadInternal
protected function ReadInternal($Buffer, $Length, $SherlockFunction)
{
if ($Buffer->Remaining() === 0) {
throw new InvalidPacketException('Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY);
}
$Header = $Buffer->GetLong();
if ($Header === -1) {
// We don't have to do anything
} else {
if ($Header === -2) {
$Packets = [];
$IsCompressed = false;
$ReadMore = false;
do {
$RequestID = $Buffer->GetLong();
switch ($this->Engine) {
case SourceQuery::GOLDSOURCE:
$PacketCountAndNumber = $Buffer->GetByte();
$PacketCount = $PacketCountAndNumber & 0xf;
$PacketNumber = $PacketCountAndNumber >> 4;
break;
case SourceQuery::SOURCE:
$IsCompressed = ($RequestID & 0x80000000) !== 0;
$PacketCount = $Buffer->GetByte();
$PacketNumber = $Buffer->GetByte() + 1;
if ($IsCompressed) {
$Buffer->GetLong();
// Split size
$PacketChecksum = $Buffer->GetUnsignedLong();
} else {
$Buffer->GetShort();
// Split size
}
break;
}
$Packets[$PacketNumber] = $Buffer->Get();
$ReadMore = $PacketCount > sizeof($Packets);
} while ($ReadMore && $SherlockFunction($Buffer, $Length));
$Data = Implode($Packets);
// TODO: Test this
if ($IsCompressed) {
// Let's make sure this function exists, it's not included in PHP by default
if (!Function_Exists('bzdecompress')) {
throw new \RuntimeException('Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.');
}
$Data = bzdecompress($Data);
if (CRC32($Data) !== $PacketChecksum) {
throw new InvalidPacketException('CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH);
}
}
$Buffer->Set(SubStr($Data, 4));
} else {
throw new InvalidPacketException('Socket read: Raw packet header mismatch. (0x' . DecHex($Header) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH);
}
}
return $Buffer;
}
示例8: execute
function execute(array $params = array())
{
$input = (string) $params['input'];
$quick = $params['quick'];
if (!is_bool($quick)) {
$quick = false;
}
return bzdecompress($input, $quick);
}
示例9: extract
/**
* Extract a Bzip2 compressed file to a given path
*
* @param string $archive Path to Bzip2 archive to extract
* @param string $destination Path to extract archive to
* @param array $options Extraction options [unused]
*
* @return boolean True if successful
* @since 11.1
*/
public function extract($archive, $destination, $options = array())
{
// Initialise variables.
$this->_data = null;
if (!extension_loaded('bz2')) {
$this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_NOT_SUPPORTED'));
return JError::raiseWarning(100, $this->get('error.message'));
}
if (!isset($options['use_streams']) || $options['use_streams'] == false) {
// Old style: read the whole file and then parse it
if (!($this->_data = JFile::read($archive))) {
$this->set('error.message', 'Unable to read archive');
return JError::raiseWarning(100, $this->get('error.message'));
}
$buffer = bzdecompress($this->_data);
unset($this->_data);
if (empty($buffer)) {
$this->set('error.message', 'Unable to decompress data');
return JError::raiseWarning(100, $this->get('error.message'));
}
if (JFile::write($destination, $buffer) === false) {
$this->set('error.message', 'Unable to write archive');
return JError::raiseWarning(100, $this->get('error.message'));
}
} else {
// New style! streams!
$input = JFactory::getStream();
$input->set('processingmethod', 'bz');
// use bzip
if (!$input->open($archive)) {
$this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_READ'));
return JError::raiseWarning(100, $this->get('error.message'));
}
$output = JFactory::getStream();
if (!$output->open($destination, 'w')) {
$this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE'));
$input->close();
// close the previous file
return JError::raiseWarning(100, $this->get('error.message'));
}
$written = 0;
do {
$this->_data = $input->read($input->get('chunksize', 8196));
if ($this->_data) {
if (!$output->write($this->_data)) {
$this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE_FILE'));
return JError::raiseWarning(100, $this->get('error.message'));
}
}
} while ($this->_data);
$output->close();
$input->close();
}
return true;
}
示例10: decode
/**
* @inheritDoc
*/
public function decode($data)
{
$data = bzdecompress($data);
if ($this->isErrorCode($data)) {
throw new DecodeFailedException("bzdecompress failed.");
}
if (!$data) {
throw new DecodeFailedException("bzdecompress returned no data.");
}
return $data;
}
示例11: reassemblePacket
/**
* Reassembles the data of a split and/or compressed packet into a single
* packet object
*
* @param array $splitPackets An array of packet data
* @param bool $isCompressed whether the data of this packet is compressed
* @param int $packetChecksum The CRC32 checksum of the decompressed
* packet data
* @throws PacketFormatException if the calculated CRC32 checksum does not
* match the expected value
* @return SteamPacket The reassembled packet
* @see packetFromData()
*/
public static function reassemblePacket($splitPackets, $isCompressed = false, $packetChecksum = 0)
{
$packetData = join('', $splitPackets);
if ($isCompressed) {
$packetData = bzdecompress($packetData);
if (crc32($packetData) != $packetChecksum) {
throw new PacketFormatException('CRC32 checksum mismatch of uncompressed packet data.');
}
}
$packetData = substr($packetData, 4);
return self::getPacketFromData($packetData);
}
示例12: populateWHoisDump
private function populateWHoisDump()
{
$this->info('Downloading and populating Afrinic WHOIS dump');
$bz2Content = $this->getContents(env('WHOIS_DB_AFRINIC_BASE_URL'));
$rawData = bzdecompress($bz2Content);
$dataParts = array_filter(explode("\n", $rawData));
// Categorise the whois data dump
foreach ($dataParts as $dataPart) {
$elementType = explode(':', $dataPart, 2)[0];
$this->whoisDump[$elementType][] = str_replace('\\t', "\t", str_replace('\\n', "\n", $dataPart));
}
}
示例13: getCSV
function getCSV($url, $method)
{
global $mdb, $redis;
$file = $redis->get("RC:{$url}");
if ($file == null) {
$file = file_get_contents($url);
$redis->setex("RC:{$url}", 900, $file);
}
$csv = bzdecompress($file);
Util::out("Parsing {$url}");
parseCSV($csv, $method);
}
示例14: decompress
/**
* @param string $file
* @return Database
* @throws IOException
* @throws \RuntimeException
*/
public function decompress(string $file) : self
{
if (($content = file_get_contents($file)) === false) {
throw new IOException('Could not read file: ' . $file);
}
if (($content = bzdecompress($content)) === false) {
throw new \RuntimeException('Could not decompress data from file: ' . $file);
}
if (file_put_contents($file, $content) === false) {
throw new IOException('Could not write data to file: ' . $file);
}
return $this;
}
示例15: extract
public static function extract($path_file)
{
$pathinfo = pathinfo($path_file);
if ($pathinfo['extension'] == 'bzip2' or $pathinfo['extension'] == 'bz2') {
$uncompressed_pathfile = $pathinfo['dirname'] . $pathinfo['basename'] . '.csv';
$compressed_str = file_get_contents($path_file);
file_put_contents($uncompressed_pathfile, bzdecompress($compressed_str));
unset($compressed_str);
$file_tree_name = $uncompressed_pathfile;
} else {
$file_tree_name = $path_file;
}
return $file_tree_name;
}