CakeFest 2024: The Official CakePHP Conference

bzcompress

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

bzcompressСжимает строку с использованием bzip2

Описание

bzcompress(string $data, int $block_size = 4, int $work_factor = 0): string|int

bzcompress() сжимает переданную строку и возвращает её в виде закодированных данных bzip2.

Список параметров

data

Сжимаемая строка.

block_size

Определяет размера блока, используемый при сжатии, должен быть числом в диапазоне от 1 до 9, где 9 даст наилучшее, но более ресурсоёмкое сжатие.

work_factor

Контролирует поведение фазы компрессии в худшем случае, когда входные данные являются часто повторяющимися. Параметр может принимать значения между 0 и 250, где 0 означает специальный случай.

Генерируемый результат не зависит от параметра work_factor и является одним и тем же.

Возвращаемые значения

Сжатая строка или код ошибки в случае неудачного завершения работы.

Примеры

Пример #1 Сжатие данных

<?php
$str
= "sample data";
$bzstr = bzcompress($str, 9);
echo
$bzstr;
?>

Смотрите также

  • bzdecompress() - Распаковывает данные, сжатые с использованием bzip2

add a note

User Contributed Notes 2 notes

up
7
uprz23 at gmail dot com
13 years ago
Comparing gzcompress/gzuncompress and bzcompress/bzdecompress, the bz combo is about 5x slower than gz.
up
4
diego a messenger do dsemmler do de
14 years ago
The blocksize parameter tells bzip to use 100 000 Byte * blocksize blocks to compress the string. In the example above we can see the output size and time needed of bz[2] to bz[9] are nearly the same, because there ware just 189 058 Byte of data to compress and in this case bz[2] to bz[9] means "compress all data et once".
So we may notice a bigger difference in speed and compression rate with bigger files.

the workfactor parameter sets, how fast bzip switches in the slower fallback algorithm, if the standard algorithm gets problems with much repetitive data. 0 means, bzip uses the default value of 30. This option is recommend.

For more information about the parameter look at http://www.bzip.org/1.0.3/html/low-level.html#bzcompress-init
To Top