Overview

Namespaces

  • splitbrain
    • PHPArchive

Classes

  • Archive
  • FileInfo
  • Tar
  • Zip

Exceptions

  • ArchiveCorruptedException
  • ArchiveIllegalCompressionException
  • ArchiveIOException
  • FileInfoException
  • Overview
  • Namespace
  • Class

Class Archive

Direct known subclasses

splitbrain\PHPArchive\Tar, splitbrain\PHPArchive\Zip
Abstract
Namespace: splitbrain\PHPArchive
Located at Archive.php
Methods summary
abstract public
# setCompression( integer $level = 9, integer $type = Archive::COMPRESS_AUTO )

Set the compression level and type

Set the compression level and type

Parameters

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

Throws

splitbrain\PHPArchive\ArchiveIllegalCompressionException
abstract public
# open( string $file )

Open an existing archive file for reading

Open an existing archive file for reading

Parameters

$file

Throws

splitbrain\PHPArchive\ArchiveIOException
abstract public splitbrain\PHPArchive\FileInfo[]
# contents( )

Read the contents of an archive

Read the contents of an archive

This function lists the files stored in the archive, and returns an indexed array of FileInfo objects

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

splitbrain\PHPArchive\FileInfo[]
abstract public array
# extract( string $outdir, integer|string $strip = '', string $exclude = '', string $include = '' )

Extract an existing archive

Extract an existing archive

The $strip parameter allows you to strip a certain number of path components from the filenames found in the archive 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 afterwards. Reopen the file with open() again if you want to do additional operations

Parameters

$outdir
the target directory for extracting
$strip
either the number of path components or a fixed prefix to strip
$exclude
a regular expression of files to exclude
$include
a regular expression of files to include

Returns

array

Throws

splitbrain\PHPArchive\ArchiveIOException
abstract public
# create( string $file = '' )

Create a new archive file

Create a new archive file

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

Parameters

$file
abstract public
# addFile( string $file, string|splitbrain\PHPArchive\FileInfo $fileinfo = '' )

Add a file to the current archive using an existing file in the filesystem

Add a file to the current archive using an existing file in the filesystem

Parameters

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

Throws

splitbrain\PHPArchive\ArchiveIOException
abstract public
# addData( string|splitbrain\PHPArchive\FileInfo $fileinfo, string $data )

Add a file to the current archive using the given $data as content

Add a file to the current archive using the given $data as content

Parameters

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

Throws

splitbrain\PHPArchive\ArchiveIOException
abstract public
# close( )

Close the archive, close all file handles

Close the archive, 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

abstract public
# getArchive( )

Returns the created in-memory archive data

Returns the created in-memory archive data

This implicitly calls close() on the Archive

abstract public
# save( string $file )

Save the created in-memory archive data

Save the created in-memory archive data

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

Parameters

$file
public
# setCallback( callable $callback )

Set a callback function to be called whenever a file is added or extracted.

Set a callback function to be called whenever a file is added or extracted.

The callback is called with a FileInfo object as parameter. You can use this to show progress info during an operation.

Parameters

$callback
Constants summary
integer COMPRESS_AUTO
# -1
integer COMPRESS_NONE
# 0
integer COMPRESS_GZIP
# 1
integer COMPRESS_BZIP
# 2
Properties summary
protected callable $callback
#
API documentation generated by ApiGen