Lines Matching +full:- +full:- +full:strip +full:- +full:components

35         if($comptype == self::COMPRESS_AUTO) $comptype = $this->filetype($file);
36 $this->compressioncheck($comptype);
38 $this->comptype = $comptype;
39 $this->file = $file;
41 if($this->comptype === self::COMPRESS_GZIP) {
42 $this->fh = @gzopen($this->file, 'rb');
43 } elseif($this->comptype === self::COMPRESS_BZIP) {
44 $this->fh = @bzopen($this->file, 'r');
46 $this->fh = @fopen($this->file, 'rb');
49 … if(!$this->fh) throw new VerboseTarIOException('Could not open file for reading: '.$this->file);
50 $this->closed = false;
75 …if($this->closed || !$this->file) throw new VerboseTarIOException('Can not read from a closed arch…
78 while($read = $this->readbytes(512)) {
79 $header = $this->parseHeader($read);
82 $this->skipbytes(ceil($header['size'] / 512) * 512);
86 $this->close();
93 … * The $strip parameter allows you to strip a certain number of path components from the filenames
94 …* found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered w…
95 * an integer is passed as $strip.
96 …* Alternatively a fixed string prefix may be passed in $strip. If the filename matches this prefix,
109 * @param int|string $strip either the number of path components or a fixed prefix to strip
115 function extract($outdir, $strip = '', $exclude = '', $include = '') { argument
116 …if($this->closed || !$this->file) throw new VerboseTarIOException('Can not read from a closed arch…
120 $striplen = strlen($strip);
124 while($dat = $this->readbytes(512)) {
126 $header = $this->parseHeader($dat);
130 // strip prefix
131 $filename = $this->cleanPath($header['filename']);
132 if(is_int($strip)) {
133 // if $strip is an integer we strip this many path components
140 $filename = join('/', array_slice($parts, $strip));
143 // ifstrip is a string, we strip a prefix here
144 … if(substr($filename, 0, $striplen) == $strip) $filename = substr($filename, $striplen);
182 fwrite($fp, $this->readbytes(512), 512);
184 … if(($header['size'] % 512) != 0) fwrite($fp, $this->readbytes(512), $header['size'] % 512);
190 … $this->skipbytes(ceil($header['size'] / 512) * 512); // the size is usually 0 for directories
193 $this->skipbytes(ceil($header['size'] / 512) * 512);
197 $this->close();
214 if($comptype == self::COMPRESS_AUTO) $comptype = $this->filetype($file);
215 $this->compressioncheck($comptype);
217 $this->comptype = $comptype;
218 $this->file = $file;
219 $this->memory = '';
220 $this->fh = 0;
222 if($this->file) {
223 if($this->comptype === self::COMPRESS_GZIP) {
224 $this->fh = @gzopen($this->file, 'wb'.$complevel);
225 } elseif($this->comptype === self::COMPRESS_BZIP) {
226 $this->fh = @bzopen($this->file, 'w');
228 $this->fh = @fopen($this->file, 'wb');
231 … if(!$this->fh) throw new VerboseTarIOException('Could not open file for writing: '.$this->file);
233 $this->writeaccess = true;
234 $this->closed = false;
246 …if($this->closed) throw new VerboseTarIOException('Archive has been closed, files can no longer be…
249 $name = $this->cleanPath($name);
257 $this->writeFileHeader(
271 $this->writebytes($packed);
288 …if($this->closed) throw new VerboseTarIOException('Archive has been closed, files can no longer be…
290 $name = $this->cleanPath($name);
293 $this->writeFileHeader(
303 $this->writebytes(pack("a512", substr($data, $s, 512)));
313 …* "Physically, an archive consists of a series of file entries terminated by an end-of-archive ent…
319 if($this->closed) return; // we did this already
322 if($this->writeaccess) {
323 $this->writebytes(pack("a512", ""));
324 $this->writebytes(pack("a512", ""));
328 if($this->file) {
329 if($this->comptype === self::COMPRESS_GZIP) {
330 gzclose($this->fh);
331 } elseif($this->comptype === self::COMPRESS_BZIP) {
332 bzclose($this->fh);
334 fclose($this->fh);
337 $this->file = '';
338 $this->fh = 0;
341 $this->closed = true;
345 * Returns the created in-memory archive data
350 $this->close();
352 if($comptype === self::COMPRESS_AUTO) $comptype = $this->comptype;
353 $this->compressioncheck($comptype);
355 if($comptype === self::COMPRESS_GZIP) return gzcompress($this->memory, $complevel);
356 if($comptype === self::COMPRESS_BZIP) return bzcompress($this->memory);
357 return $this->memory;
361 * Save the created in-memory archive data
372 if($comptype === self::COMPRESS_AUTO) $comptype = $this->filetype($file);
374 if(!file_put_contents($file, $this->getArchive($comptype, $complevel))) {
386 if($this->comptype === self::COMPRESS_GZIP) {
387 return @gzread($this->fh, $length);
388 } elseif($this->comptype === self::COMPRESS_BZIP) {
389 return @bzread($this->fh, $length);
391 return @fread($this->fh, $length);
403 if(!$this->file) {
404 $this->memory .= $data;
406 } elseif($this->comptype === self::COMPRESS_GZIP) {
407 $written = @gzwrite($this->fh, $data);
408 } elseif($this->comptype === self::COMPRESS_BZIP) {
409 $written = @bzwrite($this->fh, $data);
411 $written = @fwrite($this->fh, $data);
425 if($this->comptype === self::COMPRESS_GZIP) {
426 @gzseek($this->fh, $bytes, SEEK_CUR);
427 } elseif($this->comptype === self::COMPRESS_BZIP) {
429 @bzread($this->fh, $bytes);
431 @fseek($this->fh, $bytes, SEEK_CUR);
455 $this->writeFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L');
457 $this->writebytes(pack("a512", substr($name, $s, 512)));
483 $this->writebytes($data_first);
486 $this->writebytes($chks.$data_last);
524 // Handle Long-Link entries from GNU Tar
527 $filename = trim($this->readbytes(ceil($header['size'] / 512) * 512));
529 $block = $this->readbytes(512);
530 $return = $this->parseHeader($block);
584 if(substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
586 } elseif(substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {