SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/Drivers/Archive/Gzip.php

Copyright (C) 2017 Karmabunny Pty Ltd.

This file is a part of SproutCMS.

SproutCMS is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either
version 2 of the License, or (at your option) any later version.

For more information, visit <http://getsproutcms.com>.

This class was originally from Kohana 2.3.4
Copyright 2007-2008 Kohana Team
  1. <?php
  2. /**
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  *
  13.  * This class was originally from Kohana 2.3.4
  14.  * Copyright 2007-2008 Kohana Team
  15.  */
  16. namespace Sprout\Helpers\Drivers\Archive;
  17.  
  18. use Sprout\Helpers\Archive;
  19. use Sprout\Helpers\Drivers\ArchiveDriver;
  20.  
  21.  
  22. /**
  23.  * Archive library gzip driver.
  24.  */
  25. class Gzip implements ArchiveDriver
  26. {
  27.  
  28. public function create($paths, $filename = FALSE)
  29. {
  30. $archive = new Archive('tar');
  31.  
  32. foreach ($paths as $set)
  33. {
  34. $archive->add($set[0], $set[1]);
  35. }
  36.  
  37. $gzfile = gzencode($archive->create());
  38.  
  39. if ($filename == FALSE)
  40. {
  41. return $gzfile;
  42. }
  43.  
  44. if (substr($filename, -7) !== '.tar.gz')
  45. {
  46. // Append tar extension
  47. $filename .= '.tar.gz';
  48. }
  49.  
  50. // Create the file in binary write mode
  51. $file = fopen($filename, 'wb');
  52.  
  53. // Lock the file
  54. flock($file, LOCK_EX);
  55.  
  56. // Write the tar file
  57. $return = fwrite($file, $gzfile);
  58.  
  59. // Unlock the file
  60. flock($file, LOCK_UN);
  61.  
  62. // Close the file
  63. fclose($file);
  64.  
  65. return (bool) $return;
  66. }
  67.  
  68. public function addData($file, $name, $contents = NULL)
  69. {
  70. return FALSE;
  71. }
  72.  
  73. } // End Archive_Gzip_Driver Class
  74.