adodb-compress-bzip2.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. @version v5.20.17 31-Mar-2020
  4. @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. Contributed by Ross Smith (adodb@netebb.com).
  7. Released under both BSD license and Lesser GPL library license.
  8. Whenever there is any discrepancy between the two licenses,
  9. the BSD license will take precedence.
  10. Set tabs to 4 for best viewing.
  11. */
  12. if (!function_exists('bzcompress')) {
  13. trigger_error('bzip2 functions are not available', E_USER_ERROR);
  14. return 0;
  15. }
  16. /*
  17. */
  18. class ADODB_Compress_Bzip2 {
  19. /**
  20. */
  21. var $_block_size = null;
  22. /**
  23. */
  24. var $_work_level = null;
  25. /**
  26. */
  27. var $_min_length = 1;
  28. /**
  29. */
  30. function getBlockSize() {
  31. return $this->_block_size;
  32. }
  33. /**
  34. */
  35. function setBlockSize($block_size) {
  36. assert('$block_size >= 1');
  37. assert('$block_size <= 9');
  38. $this->_block_size = (int) $block_size;
  39. }
  40. /**
  41. */
  42. function getWorkLevel() {
  43. return $this->_work_level;
  44. }
  45. /**
  46. */
  47. function setWorkLevel($work_level) {
  48. assert('$work_level >= 0');
  49. assert('$work_level <= 250');
  50. $this->_work_level = (int) $work_level;
  51. }
  52. /**
  53. */
  54. function getMinLength() {
  55. return $this->_min_length;
  56. }
  57. /**
  58. */
  59. function setMinLength($min_length) {
  60. assert('$min_length >= 0');
  61. $this->_min_length = (int) $min_length;
  62. }
  63. /**
  64. */
  65. function __construct($block_size = null, $work_level = null, $min_length = null) {
  66. if (!is_null($block_size)) {
  67. $this->setBlockSize($block_size);
  68. }
  69. if (!is_null($work_level)) {
  70. $this->setWorkLevel($work_level);
  71. }
  72. if (!is_null($min_length)) {
  73. $this->setMinLength($min_length);
  74. }
  75. }
  76. /**
  77. */
  78. function write($data, $key) {
  79. if (strlen($data) < $this->_min_length) {
  80. return $data;
  81. }
  82. if (!is_null($this->_block_size)) {
  83. if (!is_null($this->_work_level)) {
  84. return bzcompress($data, $this->_block_size, $this->_work_level);
  85. } else {
  86. return bzcompress($data, $this->_block_size);
  87. }
  88. }
  89. return bzcompress($data);
  90. }
  91. /**
  92. */
  93. function read($data, $key) {
  94. return $data ? bzdecompress($data) : $data;
  95. }
  96. }
  97. return 1;