function _rewind()
 {
     if (is_resource($this->_file)) {
         if ($this->_compress_type == 'gz') {
             @gzrewind($this->_file);
         } else {
             if ($this->_compress_type == 'bz2') {
                 // ----- Replace missing bztell() and bzseek()
             } else {
                 if ($this->_compress_type == 'none') {
                     @rewind($this->_file);
                 } else {
                     $this->_error('Unknown or missing compression type (' . $this->_compress_type . ')');
                 }
             }
         }
     }
     return true;
 }
Exemple #2
0
<?php

$filename = "gzread_variation1.txt.gz";
$h = gzopen($filename, 'w');
$str = "Here is the string to be written. ";
var_dump(gzread($h, 100));
gzwrite($h, $str);
var_dump(gzread($h, 100));
gzrewind($h);
var_dump(gzread($h, 100));
gzclose($h);
$h = gzopen($filename, 'r');
gzpassthru($h);
gzclose($h);
echo "\n";
unlink($filename);
?>
===DONE===
 function doRewind()
 {
     return @gzrewind($this->File);
 }
Exemple #4
0
<?php

$f = dirname(__FILE__) . "/004.txt.gz";
$h = gzopen($f, 'r');
$extra_arg = 'nothing';
var_dump(gzrewind($h, $extra_arg));
var_dump(gzrewind());
gzclose($h);
?>
===DONE===
 /**
  * Write the sitemap into a file
  *
  * @access  protected
  * @param   string     $filename the name of the sitemap file
  * @param   string     $sitemap  the content of the sitemap
  * @return  boolean              TRUE = success, FALSE = otherwise
  */
 function _write($filename, $sitemap)
 {
     $retval = FALSE;
     if (!@touch($filename)) {
         COM_errorLog(__CLASS__ . ': Cannot write the sitemap file: ' . $filename);
         return $retval;
     }
     // If file name is '*.gz', then we use gz* functions
     $parts = pathinfo($filename);
     if (isset($parts['extension']) and strtolower($parts['extension']) == 'gz' and is_callable('gzopen')) {
         // Save as a gzipped file
         $gp = gzopen($filename, 'r+b');
         if ($gp === FALSE) {
             COM_errorLog(__CLASS__ . ': Cannot create the sitemap file: ' . $filename);
         } else {
             if (flock($gp, LOCK_EX)) {
                 ftruncate($gp, 0);
                 gzrewind($gp);
                 gzwrite($gp, $sitemap);
                 gzclose($gp);
                 $retval = TRUE;
             } else {
                 COM_errorLog(__CLASS__ . ': Cannot lock the sitemap file for writing: ' . $filename);
             }
         }
     } else {
         $fp = fopen($filename, 'r+b');
         if ($fp === FALSE) {
             COM_errorLog(__CLASS__ . ': Cannot create the sitemap file: ' . $filename);
         } else {
             if (flock($fp, LOCK_EX)) {
                 ftruncate($fp, 0);
                 rewind($fp);
                 fwrite($fp, $sitemap);
                 fclose($fp);
                 $retval = TRUE;
             } else {
                 COM_errorLog(__CLASS__ . ': Cannot lock the sitemap file for writing: ' . $filename);
             }
         }
     }
     return $retval;
 }
 /**
  * Write a sitemap into a file
  *
  * @param   string     $filename the name of the sitemap file
  * @param   string     $sitemap  the content of the sitemap
  * @return  boolean              true = success, false = otherwise
  */
 protected function write($filename, $sitemap)
 {
     $retval = false;
     if (!@touch($filename)) {
         COM_errorLog(__METHOD__ . ': Cannot write into the sitemap file: ' . $filename);
         return $retval;
     }
     // If file name is '*.gz', then we use Zlib functions
     $parts = pathinfo($filename);
     if (isset($parts['extension']) && strtolower($parts['extension']) === 'gz' && is_callable('gzopen')) {
         // Save as a gzipped file
         $gp = @gzopen($filename, 'r+b');
         if ($gp === false) {
             COM_errorLog(__METHOD__ . ': Cannot create the sitemap file: ' . $filename);
         } else {
             if (flock($gp, LOCK_EX)) {
                 ftruncate($gp, 0);
                 gzrewind($gp);
                 gzwrite($gp, $sitemap);
                 flock($gp, LOCK_UN);
                 gzclose($gp);
                 $retval = true;
             } else {
                 COM_errorLog(__METHOD__ . ': Cannot lock the sitemap file for writing: ' . $filename);
             }
         }
     } else {
         $fp = @fopen($filename, 'r+b');
         if ($fp === false) {
             COM_errorLog(__METHOD__ . ': Cannot create the sitemap file: ' . $filename);
         } else {
             if (flock($fp, LOCK_EX)) {
                 ftruncate($fp, 0);
                 rewind($fp);
                 fwrite($fp, $sitemap);
                 fflush($fp);
                 flock($fp, LOCK_UN);
                 fclose($fp);
                 $retval = true;
             } else {
                 COM_errorLog(__METHOD__ . ': Cannot lock the sitemap file for writing: ' . $filename);
             }
         }
     }
     return $retval;
 }
 /**
  * Sets the file position indicator for fp to the beginning of the 
  * file stream. 
  * 
  * This function is identical to a call of $f->seek(0, SEEK_SET)
  *
  * @throws  io.IOException in case of an error
  */
 public function rewind()
 {
     if (FALSE === ($result = gzrewind($this->_fd))) {
         throw new IOException('cannot rewind file pointer');
     }
     return TRUE;
 }
Exemple #8
0
 /**
  * Sets the file position indicator for fp to the beginning of the 
  * file stream. 
  * 
  * This function is identical to a call of $f->seek(0, SEEK_SET)
  *
  * @throws  io.IOException in case of an error
  */
 public function rewind()
 {
     if (false === ($result = gzrewind($this->_fd))) {
         throw new IOException('cannot rewind file pointer');
     }
     return true;
 }
Exemple #9
0
var_dump(readgzfile($tmpfile));
$zipped = gzencode("testing gzencode");
VS(gzdecode($zipped), "testing gzencode");
$f = gzopen($tmpfile, "w");
VERIFY($f !== false);
gzputs($f, "testing gzputs\n");
gzwrite($f, "<html>testing gzwrite</html>\n");
gzclose($f);
$f = gzopen($tmpfile, "r");
VS(gzread($f, 7), "testing");
VS(gzgetc($f), " ");
VS(gzgets($f), "gzputs\n");
VS(gzgetss($f), "testing gzwrite\n");
VS(gztell($f), 44);
VERIFY(gzeof($f));
VERIFY(gzrewind($f));
VS(gztell($f), 0);
VERIFY(!gzeof($f));
gzseek($f, -7, SEEK_END);
VS(gzgets($f), "testing gzputs\n");
gzclose($f);
$f = gzopen(__DIR__ . "/test_ext_zlib.gz", "r");
gzpassthru($f);
$compressable = str_repeat('A', 1024);
$s = $compressable;
$t = nzcompress($s);
VERIFY(strlen($t) < strlen($s));
$u = nzuncompress($t);
VS($u, $s);
$compressable = str_repeat('\\0', 1024);
$bs = $compressable;
Exemple #10
0
 /**
  * Resets the input stream.
  */
 public function reset()
 {
     if (!is_resource($this->_stream)) {
         throw new Opl_Stream_Exception('Input stream is not opened.');
     }
     gzrewind($this->_stream);
 }
Exemple #11
0
 /**
  * Rewinds the file pointer to the beginning.
  */
 function rewind()
 {
     if (gzrewind($this->fh) === false) {
         throw new \Aimeos\MW\Container\Exception(sprintf('Unable to rewind file "%1$s"', $this->getResource()));
     }
     $this->position = 0;
     $this->data = $this->getData();
 }
Exemple #12
0
 /**
  * Go back to the start of reading an open archive
  **/
 function rewind()
 {
     if ($this->file_writing) {
         return;
     }
     if ($this->file_handle === false) {
         return;
     }
     if ($this->gz_mode) {
         gzrewind($this->file_handle);
     } else {
         rewind($this->file_handle);
     }
     $this->seek_length = 0;
 }
Exemple #13
0
 /**
  * Rewinds the file pointer to the beginning.
  */
 function rewind()
 {
     if (gzrewind($this->_fh) === false) {
         throw new MW_Container_Exception(sprintf('Unable to rewind file "%1$s"', $this->getResource()));
     }
     $this->_position = 0;
     $this->_data = $this->_getData();
 }
Exemple #14
0
 /**
  * Rewind the position of a gz-file pointer
  *
  * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
  *                     successfully opened by gzopen.
  *
  * @return bool
  */
 public function gzrewind($zp) : bool
 {
     return gzrewind($zp);
 }
Exemple #15
0
<?php

$f = "temp2.txt.gz";
$h = gzopen($f, 'w');
gzwrite($h, 'The first string.');
var_dump(gzrewind($h));
gzwrite($h, 'The second string.');
gzclose($h);
$h = gzopen($f, 'r');
gzpassthru($h);
gzclose($h);
unlink($f);
echo "\n";
?>
===DONE===
 public function rewind($zp = '')
 {
     if (!is_resource($zp)) {
         return Error::set(lang('Error', 'resourceParameter', '1.(zp)'));
     }
     return gzrewind($zp);
 }