Bz.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Class to work with bzip2 archives
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Framework\Archive;
  12. class Bz extends \Magento\Framework\Archive\AbstractArchive implements \Magento\Framework\Archive\ArchiveInterface
  13. {
  14. /**
  15. * Pack file by BZIP2 compressor.
  16. *
  17. * @param string $source
  18. * @param string $destination
  19. * @return string
  20. */
  21. public function pack($source, $destination)
  22. {
  23. $fileReader = new \Magento\Framework\Archive\Helper\File($source);
  24. $fileReader->open('r');
  25. $archiveWriter = new \Magento\Framework\Archive\Helper\File\Bz($destination);
  26. $archiveWriter->open('w');
  27. while (!$fileReader->eof()) {
  28. $archiveWriter->write($fileReader->read());
  29. }
  30. $fileReader->close();
  31. $archiveWriter->close();
  32. return $destination;
  33. }
  34. /**
  35. * Unpack file by BZIP2 compressor.
  36. *
  37. * @param string $source
  38. * @param string $destination
  39. * @return string
  40. */
  41. public function unpack($source, $destination)
  42. {
  43. if (is_dir($destination)) {
  44. $file = $this->getFilename($source);
  45. $destination = $destination . $file;
  46. }
  47. $archiveReader = new \Magento\Framework\Archive\Helper\File\Bz($source);
  48. $archiveReader->open('r');
  49. $fileWriter = new \Magento\Framework\Archive\Helper\File($destination);
  50. $fileWriter->open('w');
  51. while (!$archiveReader->eof()) {
  52. $fileWriter->write($archiveReader->read());
  53. }
  54. return $destination;
  55. }
  56. }