[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/splitbrain/php-archive/src/ -> Tar.php (summary)

(no description)

File Size: 716 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Tar:: (20 methods):
  setCompression()
  open()
  contents()
  yieldContents()
  extract()
  create()
  addFile()
  addData()
  close()
  getArchive()
  save()
  readbytes()
  writebytes()
  skipbytes()
  writeFileHeader()
  writeRawFileHeader()
  parseHeader()
  header2fileinfo()
  compressioncheck()
  filetype()


Class: Tar  - X-Ref

Class Tar

Creates or extracts Tar archives. Supports gz and bzip compression

Long pathnames (>100 chars) are supported in POSIX ustar and GNU longlink formats.

setCompression($level = 9, $type = Archive::COMPRESS_AUTO)   X-Ref
Sets the compression to use

param: int $level Compression level (0 to 9)
param: int $type Type of compression to use (use COMPRESS_* constants)

open($file)   X-Ref
Open an existing TAR file for reading

param: string $file

contents()   X-Ref
Read the contents of a TAR archive

This function lists the files stored in the archive

The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams.
Reopen the file with open() again if you want to do additional operations

returns: FileInfo[]

yieldContents()   X-Ref
Read the contents of a TAR archive and return each entry using yield
for memory efficiency.

see: contents()
returns: FileInfo[]

extract($outdir, $strip = '', $exclude = '', $include = '')   X-Ref
Extract an existing TAR archive

The $strip parameter allows you to strip a certain number of path components from the filenames
found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered when
an integer is passed as $strip.
Alternatively a fixed string prefix may be passed in $strip. If the filename matches this prefix,
the prefix will be stripped. It is recommended to give prefixes with a trailing slash.

By default this will extract all files found in the archive. You can restrict the output using the $include
and $exclude parameter. Both expect a full regular expression (including delimiters and modifiers). If
$include is set only files that match this expression will be extracted. Files that match the $exclude
expression will never be extracted. Both parameters can be used in combination. Expressions are matched against
stripped filenames as described above.

The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams.
Reopen the file with open() again if you want to do additional operations

param: string $outdir the target directory for extracting
param: int|string $strip either the number of path components or a fixed prefix to strip
param: string $exclude a regular expression of files to exclude
param: string $include a regular expression of files to include
return: FileInfo[]

create($file = '')   X-Ref
Create a new TAR file

If $file is empty, the tar file will be created in memory

param: string $file

addFile($file, $fileinfo = '')   X-Ref
Add a file to the current TAR archive using an existing file in the filesystem

param: string $file path to the original file
param: string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original

addData($fileinfo, $data)   X-Ref
Add a file to the current TAR archive using the given $data as content

param: string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data
param: string          $data     binary content of the file to add

close()   X-Ref
Add the closing footer to the archive if in write mode, close all file handles

After a call to this function no more data can be added to the archive, for
read access no reading is allowed anymore

"Physically, an archive consists of a series of file entries terminated by an end-of-archive entry, which
consists of two 512 blocks of zero bytes"

link: http://www.gnu.org/software/tar/manual/html_chapter/tar_8.html#SEC134

getArchive()   X-Ref
Returns the created in-memory archive data

This implicitly calls close() on the Archive

save($file)   X-Ref
Save the created in-memory archive data

Note: It more memory effective to specify the filename in the create() function and
let the library work on the new file directly.

param: string $file

readbytes($length)   X-Ref
Read from the open file pointer

param: int $length bytes to read
return: string

writebytes($data)   X-Ref
Write to the open filepointer or memory

param: string $data
return: int number of bytes written

skipbytes($bytes)   X-Ref
Skip forward in the open file pointer

This is basically a wrapper around seek() (and a workaround for bzip2)

param: int $bytes seek to this position

writeFileHeader(FileInfo $fileinfo)   X-Ref
Write the given file meta data as header

param: FileInfo $fileinfo

writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '')   X-Ref
Write a file header to the stream

param: string $name
param: int $uid
param: int $gid
param: int $perm
param: int $size
param: int $mtime
param: string $typeflag Set to '5' for directories

parseHeader($block)   X-Ref
Decode the given tar file header

param: string $block a 512 byte block containing the header data
return: array|false returns false when this was a null block

header2fileinfo($header)   X-Ref
Creates a FileInfo object from the given parsed header

param: $header
return: FileInfo

compressioncheck($comptype)   X-Ref
Checks if the given compression type is available and throws an exception if not

param: $comptype

filetype($file)   X-Ref
Guesses the wanted compression from the given file

Uses magic bytes for existing files, the file extension otherwise

You don't need to call this yourself. It's used when you pass Archive::COMPRESS_AUTO somewhere

param: string $file
return: int