Decompresses a string.
public decompress ( string $text ) : string | ||
$text | string | The compressed string. |
Résultat | string | The decompressed string. |
/** * Unpack a string. * * @param string $data The packed string. * * @return mixed The unpacked data. * @throws Horde_Pack_Exception */ public function unpack($data) { if (!$data) { return $data; } if (is_string($data)) { $mask = unpack('C*', $data[0]); $mask = reset($mask); $data = substr($data, 1); if ($mask & self::COMPRESS_MASK) { $data = self::$_compress->decompress($data); $mask ^= self::COMPRESS_MASK; } if (isset(self::$_drivers[$mask])) { try { return self::$_drivers[$mask]->unpack($data); } catch (Horde_Pack_Exception $e) { throw $e; } catch (Exception $e) { /* Unknown exceptions are handled with the throw below. */ } } } throw new Horde_Pack_Exception('Could not unpack data'); }
/** */ public function get($mailbox, $uids, $fields, $uidvalid) { $this->getMetaData($mailbox, $uidvalid, array('uidvalid')); $query = $this->_baseSql($mailbox, self::MSG_TABLE); $query[0] = 'SELECT t.data, t.msguid ' . $query[0]; $uid_query = array(); foreach ($uids as $val) { $uid_query[] = 't.msguid = ?'; $query[1][] = strval($val); } $query[0] .= ' AND (' . implode(' OR ', $uid_query) . ')'; $compress = new Horde_Compress_Fast(); $out = array(); try { $columns = $this->_db->columns(self::MSG_TABLE); $res = $this->_db->select($query[0], $query[1]); foreach ($res as $row) { try { $out[$row['msguid']] = @unserialize($compress->decompress($columns['data']->binaryToString($row['data']))); } catch (Exception $e) { } } } catch (Horde_Db_Exception $e) { } return $out; }
/** * Unpack a string. * * @param string $data The packed string. * * @return mixed The unpacked data. * @throws Horde_Pack_Exception */ public function unpack($data) { if (!$data) { return $data; } if (is_string($data)) { $mask = unpack('C*', $data[0]); $mask = reset($mask); $data = substr($data, 1); if ($mask & self::COMPRESS_MASK) { $data = self::$_compress->decompress($data); $mask ^= self::COMPRESS_MASK; } if (isset(self::$_drivers[$mask])) { return self::$_drivers[$mask]->unpack($data); } } throw new Horde_Pack_Exception('Could not unpack data'); }
public function testLz4DriverDecompress() { try { $ob = new Horde_Compress_Fast(array('drivers' => array('Horde_Compress_Fast_Lz4'))); } catch (Horde_Compress_Fast_Exception $e) { $this->markTestSkipped('Horde LZ4 extension not available.'); } $this->assertEquals($this->compress_text, $ob->decompress(horde_lz4_compress($this->compress_text))); try { $ob->decompress(new stdClass()); $this->fail('Expected exception.'); } catch (Horde_Compress_Fast_Exception $e) { } }
/** * Convert data from/to storage format. * * @param mixed|MongoBinData $data The data object. * * @return mixed|MongoBinData The converted data. */ protected function _value($data) { static $compress; if (!isset($compress)) { $compress = new Horde_Compress_Fast(); } return $data instanceof MongoBinData ? @unserialize($compress->decompress($data->bin)) : new MongoBinData($compress->compress(serialize($data)), MongoBinData::BYTE_ARRAY); }
/** * Retrieve cached data. * * @todo Change default lifetime to 0 * * @param string $key Object ID to query. * @param integer $lifetime Lifetime of the object in seconds. * * @return mixed Cached data, or false if none was found. */ public function get($key, $lifetime = 1) { $res = $this->_storage->get($key, $lifetime); if (empty($this->_params['compress']) || !is_string($res)) { return $res; } $compress = new Horde_Compress_Fast(); return $compress->decompress($res); }