Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Filter_Compress_Bz2 Class Reference
Inheritance diagram for Zend_Filter_Compress_Bz2:
Zend_Filter_Compress_CompressAbstract Zend_Filter_Compress_CompressInterface

Public Member Functions

 __construct ($options=null)
 
 getBlocksize ()
 
 setBlocksize ($blocksize)
 
 getArchive ()
 
 setArchive ($archive)
 
 compress ($content)
 
 decompress ($content)
 
 toString ()
 
- Public Member Functions inherited from Zend_Filter_Compress_CompressAbstract
 __construct ($options=null)
 
 getOptions ($option=null)
 
 setOptions (array $options)
 

Protected Attributes

 $_options
 

Detailed Description

Definition at line 35 of file Bz2.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Class constructor

Parameters
array | Zend_Config$options(Optional) Options to set

Definition at line 56 of file Bz2.php.

57  {
58  if (!extension_loaded('bz2')) {
59  #require_once 'Zend/Filter/Exception.php';
60  throw new Zend_Filter_Exception('This filter needs the bz2 extension');
61  }
62  parent::__construct($options);
63  }

Member Function Documentation

◆ compress()

compress (   $content)

Compresses the given content

Parameters
string$content
Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 120 of file Bz2.php.

121  {
122  $archive = $this->getArchive();
123  if (!empty($archive)) {
124  $file = bzopen($archive, 'w');
125  if (!$file) {
126  #require_once 'Zend/Filter/Exception.php';
127  throw new Zend_Filter_Exception("Error opening the archive '" . $archive . "'");
128  }
129 
130  bzwrite($file, $content);
131  bzclose($file);
132  $compressed = true;
133  } else {
134  $compressed = bzcompress($content, $this->getBlocksize());
135  }
136 
137  if (is_int($compressed)) {
138  #require_once 'Zend/Filter/Exception.php';
139  throw new Zend_Filter_Exception('Error during compression');
140  }
141 
142  return $compressed;
143  }

◆ decompress()

decompress (   $content)

Decompresses the given content

Parameters
string$content
Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 151 of file Bz2.php.

152  {
153  $archive = $this->getArchive();
154  if (@file_exists($content)) {
155  $archive = $content;
156  }
157 
158  if (@file_exists($archive)) {
159  $file = bzopen($archive, 'r');
160  if (!$file) {
161  #require_once 'Zend/Filter/Exception.php';
162  throw new Zend_Filter_Exception("Error opening the archive '" . $content . "'");
163  }
164 
165  $compressed = bzread($file);
166  bzclose($file);
167  } else {
168  $compressed = bzdecompress($content);
169  }
170 
171  if (is_int($compressed)) {
172  #require_once 'Zend/Filter/Exception.php';
173  throw new Zend_Filter_Exception('Error during decompression');
174  }
175 
176  return $compressed;
177  }

◆ getArchive()

getArchive ( )

Returns the set archive

Returns
string

Definition at line 97 of file Bz2.php.

98  {
99  return $this->_options['archive'];
100  }

◆ getBlocksize()

getBlocksize ( )

Returns the set blocksize

Returns
integer

Definition at line 70 of file Bz2.php.

71  {
72  return $this->_options['blocksize'];
73  }

◆ setArchive()

setArchive (   $archive)

Sets the archive to use for de-/compression

Parameters
string$archiveArchive to use
Returns
Zend_Filter_Compress_Bz2

Definition at line 108 of file Bz2.php.

109  {
110  $this->_options['archive'] = (string) $archive;
111  return $this;
112  }

◆ setBlocksize()

setBlocksize (   $blocksize)

Sets a new blocksize

Parameters
integer$level
Returns
Zend_Filter_Compress_Bz2

Definition at line 81 of file Bz2.php.

82  {
83  if (($blocksize < 0) || ($blocksize > 9)) {
84  #require_once 'Zend/Filter/Exception.php';
85  throw new Zend_Filter_Exception('Blocksize must be between 0 and 9');
86  }
87 
88  $this->_options['blocksize'] = (int) $blocksize;
89  return $this;
90  }

◆ toString()

toString ( )

Returns the adapter name

Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 184 of file Bz2.php.

185  {
186  return 'Bz2';
187  }

Field Documentation

◆ $_options

$_options
protected
Initial value:
= array(
'blocksize' => 4,
'archive' => null,
)

Definition at line 46 of file Bz2.php.


The documentation for this class was generated from the following file: