/**
* 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');
}