BZ.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace ZN\Compression\Drivers;
  3. use ZN\Compression\CompressInterface;
  4. class BZDriver implements CompressInterface
  5. {
  6. //----------------------------------------------------------------------------------------------------
  7. //
  8. // Yazar : Ozan UYKUN <ozanbote@windowslive.com> | <ozanbote@gmail.com>
  9. // Site : www.zntr.net
  10. // Lisans : The MIT License
  11. // Telif Hakkı: Copyright (c) 2012-2016, zntr.net
  12. //
  13. //----------------------------------------------------------------------------------------------------
  14. public function extract($source = NULL, $target = NULL, $password = NULL)
  15. {
  16. // Bu sürücü tarafından desteklenmemektedir!
  17. return false;
  18. }
  19. /******************************************************************************************
  20. * WRITE *
  21. *******************************************************************************************
  22. | Genel Kullanım: Veriyi sıkıştırarak dosyaya yazar. |
  23. | |
  24. ******************************************************************************************/
  25. public function write($file = '', $data = '', $mode = NULL)
  26. {
  27. if( ! is_string($file) || empty($file) )
  28. {
  29. return \Errors::set('Error', 'stringParameter', '1.(file)');
  30. }
  31. if( ! is_scalar($data) )
  32. {
  33. return \Errors::set('Error', 'valueParameter', '2.(data)');
  34. }
  35. $open = bzopen($file, 'w');
  36. if( empty($open) )
  37. {
  38. return \Errors::set('Error', 'fileNotFound', $file);
  39. }
  40. $return = bzwrite($open, $data, strlen($data));
  41. bzclose($open);
  42. return $return;
  43. }
  44. /******************************************************************************************
  45. * READ *
  46. *******************************************************************************************
  47. | Genel Kullanım: Sıkıştırılmış veriyi dosyadan okur. |
  48. | |
  49. ******************************************************************************************/
  50. public function read($file = '', $length = 1024, $type = NULL)
  51. {
  52. if( ! is_string($file) || empty($file) )
  53. {
  54. return \Errors::set('Error', 'stringParameter', '1.(file)');
  55. }
  56. if( ! is_numeric($length) )
  57. {
  58. return \Errors::set('Error', 'numericParameter', '2.(length)');
  59. }
  60. $open = bzopen($file, 'r');
  61. if( empty($open) )
  62. {
  63. return \Errors::set('Error', 'fileNotFound', $file);
  64. }
  65. $return = bzread($open, $length);
  66. bzclose($open);
  67. return $return;
  68. }
  69. /******************************************************************************************
  70. * COMPRESS *
  71. *******************************************************************************************
  72. | Genel Kullanım: Verilen dizgeyi bzip2 kodlamalı olarak sıkıştırır. |
  73. | |
  74. ******************************************************************************************/
  75. public function compress($data = '', $blockSize = 4, $workFactor = 0)
  76. {
  77. if( ! is_scalar($data) )
  78. {
  79. return \Errors::set('Error', 'valueParameter', '1.(data)');
  80. }
  81. if( ! is_numeric($blockSize) || ! is_numeric($workFactor) )
  82. {
  83. return \Errors::set('Error', 'numericParameter', '2.(blockSize) & 3.(workFactor)');
  84. }
  85. return bzcompress($data, $blockSize, $workFactor);
  86. }
  87. /******************************************************************************************
  88. * UNCOMPRESS *
  89. *******************************************************************************************
  90. | Genel Kullanım: Bzip2 ile sıkıştırılmış veriyi açar. |
  91. | |
  92. ******************************************************************************************/
  93. public function uncompress($data = '', $small = 0)
  94. {
  95. if( ! is_scalar($data) )
  96. {
  97. return \Errors::set('Error', 'valueParameter', '1.(data)');
  98. }
  99. if( ! is_numeric($small) )
  100. {
  101. return \Errors::set('Error', 'numericParameter', '2.(small)');
  102. }
  103. return bzdecompress($data, $small);
  104. }
  105. public function encode($data = NULL, $level = NULL, $encoding = NULL)
  106. {
  107. // Bu sürücü tarafından desteklenmemektedir!
  108. return false;
  109. }
  110. public function decode($data = NULL, $length = NULL)
  111. {
  112. // Bu sürücü tarafından desteklenmemektedir!
  113. return false;
  114. }
  115. public function deflate($data = NULL, $level = NULL, $encoding = NULL)
  116. {
  117. // Bu sürücü tarafından desteklenmemektedir!
  118. return false;
  119. }
  120. public function inflate($data = NULL, $length = NULL)
  121. {
  122. // Bu sürücü tarafından desteklenmemektedir!
  123. return false;
  124. }
  125. }