[ Index ] |
PHP Cross Reference of DokuWiki |
[Source view] [Print] [Project Stats]
(no description)
File Size: | 1026 lines (34 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
Zip:: (27 methods):
setCompression()
open()
contents()
yieldContents()
extract()
create()
addFile()
addData()
close()
getArchive()
save()
readCentralDir()
readCentralFileHeader()
readFileHeader()
parseExtra()
header2fileinfo()
cpToUtf8()
utf8ToCp()
writebytes()
writebytesAt()
dataOffset()
makeDosTime()
makeUnixTime()
makeCentralFileRecord()
makeLocalFileHeader()
makeCrcAndSize()
encodeFilename()
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[] |
yieldContents() X-Ref |
Read the contents of a ZIP archive and return each entry using yield for memory efficiency. see: contents() 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. return: FileInfo[] 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 |
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. return: array param: array $header the central file header read previously (see above) |
parseExtra($header) X-Ref |
Parse the extra headers into fields return: array param: string $header |
header2fileinfo($header) X-Ref |
Create fileinfo object from header data return: FileInfo param: $header |
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. return: string param: $string |
utf8ToCp($string) X-Ref |
Convert the given UTF-8 encoded string to CP437 Same caveats as for cpToUtf8() apply return: string param: $string |
writebytes($data) X-Ref |
Write to the open filepointer or memory return: int number of bytes written param: string $data |
writebytesAt($data, $offset) X-Ref |
Write to the open filepointer or memory at the specified offset return: int number of bytes written param: string $data param: int $offset |
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 return: int param: $time |
makeUnixTime($mdate = null, $mtime = null) X-Ref |
Create a UNIX timestamp from a DOS timestamp return: int param: $mdate param: $mtime |
makeCentralFileRecord($offset, $ts, $crc, $len, $clen, $name, $comp = null) X-Ref |
Returns a local file header for the given data return: string 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 |
makeLocalFileHeader($ts, $crc, $len, $clen, $name, $comp = null) X-Ref |
Returns a local file header for the given data return: string 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 |
makeCrcAndSize($crc, $len, $clen) X-Ref |
Returns only a part of the local file header containing the CRC, size and compressed size. Used to update these fields for an already written header. return: string 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 |
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 return: array($filename, $extra) param: $original |