[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

(no description)

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

Defines 1 class

Zip:: (24 methods):
  setCompression()
  open()
  contents()
  extract()
  create()
  addFile()
  addData()
  close()
  getArchive()
  save()
  readCentralDir()
  readCentralFileHeader()
  readFileHeader()
  parseExtra()
  header2fileinfo()
  cpToUtf8()
  utf8ToCp()
  writebytes()
  dataOffset()
  makeDosTime()
  makeUnixTime()
  makeCentralFileRecord()
  makeLocalFileHeader()
  encodeFilename()


Class: Zip  - X-Ref

Class Zip

Creates or extracts Zip archives

for specs see http://www.pkware.com/appnote

setCompression($level = 9, $type = Archive::COMPRESS_AUTO)   X-Ref
Set the compression level.

Compression Type is ignored for ZIP

You can call this function before adding each file to set differen compression levels
for each file.

param: int $level Compression level (0 to 9)
param: int $type  Type of compression to use ignored for ZIP

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

param: string $file

contents()   X-Ref
Read the contents of a ZIP 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, for API compatibility with TAR files
Reopen the file with open() again if you want to do additional operations

return: FileInfo[]

extract($outdir, $strip = '', $exclude = '', $include = '')   X-Ref
Extract an existing ZIP 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.

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 ZIP file

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

param: string $file

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

param: string $file path to the original file
param: string|FileInfo $fileinfo either the name to use 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 Zip 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

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's more memory effective to specify the filename in the create() function and
let the library work on the new file directly.

param: $file

readCentralDir()   X-Ref
Read the central directory

This key-value list contains general information about the ZIP file

return: array

readCentralFileHeader()   X-Ref
Read the next central file header

Assumes the current file pointer is pointing at the right position

return: array

readFileHeader($header)   X-Ref
Reads the local file header

This header precedes each individual file inside the zip file. Assumes the current file pointer is pointing at
the right position already. Enhances the given central header with the data found at the local header.

param: array $header the central file header read previously (see above)
return: array

parseExtra($header)   X-Ref
Parse the extra headers into fields

param: string $header
return: array

header2fileinfo($header)   X-Ref
Create fileinfo object from header data

param: $header
return: FileInfo

cpToUtf8($string)   X-Ref
Convert the given CP437 encoded string to UTF-8

Tries iconv with the correct encoding first, falls back to mbstring with CP850 which is
similar enough. CP437 seems not to be available in mbstring. Lastly falls back to keeping the
string as is, which is still better than nothing.

On some systems iconv is available, but the codepage is not. We also check for that.

param: $string
return: string

utf8ToCp($string)   X-Ref
Convert the given UTF-8 encoded string to CP437

Same caveats as for cpToUtf8() apply

param: $string
return: string

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

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

dataOffset()   X-Ref
Current data pointer position

return: int

makeDosTime($time)   X-Ref
Create a DOS timestamp from a UNIX timestamp

DOS timestamps start at 1980-01-01, earlier UNIX stamps will be set to this date

param: $time
return: int

makeUnixTime($mdate = null, $mtime = null)   X-Ref
Create a UNIX timestamp from a DOS timestamp

param: $mdate
param: $mtime
return: int

makeCentralFileRecord($offset, $ts, $crc, $len, $clen, $name, $comp = null)   X-Ref
Returns a local file header for the given data

param: int $offset location of the local header
param: int $ts unix timestamp
param: int $crc CRC32 checksum of the uncompressed data
param: int $len length of the uncompressed data
param: int $clen length of the compressed data
param: string $name file name
param: boolean|null $comp if compression is used, if null it's determined from $len != $clen
return: string

makeLocalFileHeader($ts, $crc, $len, $clen, $name, $comp = null)   X-Ref
Returns a local file header for the given data

param: int $ts unix timestamp
param: int $crc CRC32 checksum of the uncompressed data
param: int $len length of the uncompressed data
param: int $clen length of the compressed data
param: string $name file name
param: boolean|null $comp if compression is used, if null it's determined from $len != $clen
return: string

encodeFilename($original)   X-Ref
Returns an allowed filename and an extra field header

When encoding stuff outside the 7bit ASCII range it needs to be placed in a separate
extra field

param: $original
return: array($filename, $extra)