Overview  Package SS_ZIP class

SS_ZIP

Class ss_zip

SS_ZIP.ss_zip

class ss_zip

SS_ZIP class is designed to work with ZIP archives

Author:
Yuriy Horobey, smiledsoft.com

Field Summary
public var$zipfile

contains whole zipfile

public var$complevel

compression level

public var$cnt

entry counter

public var$offset

current offset in zipdata segment

public var$idx

index of current entry

public var$zipdata

ZipData segment, each element of this array contains local file header plus zipped data

public var$cdir

central directory array

Method Summary
public voidss_zip

constructor

public voidclear

Resets the objec, clears all the structures

public voidopen

opens zip file.

public voidsave

saves to the disc or sends zipfile to the browser.

public voidadd_data

adds data to zip file

public voidadd_file

adds a file to the archive

public strarchive

compile the arcive.

public intseek_idx

changes pointer to current entry.

public arrayread

Reads an entry from the arcive which is pointed by inner index pointer.

public boolremove

Removes entry from the archive.

public arrayextract_data

extracts data from the archive and return it as a string.

public voidextract_file

extracts the entry and creates it in the file system.

private void_check_idx
private void_write
Field Detail

zipfile

public var $zipfile = ""

contains whole zipfile

See Also:
ss_zip::archive, ss_zip::ss_zip

complevel

public var $complevel = 6

compression level


cnt

public var $cnt

entry counter


offset

public var $offset

current offset in zipdata segment


idx

public var $idx

index of current entry

See Also:
ss_zip::read

zipdata

public var $zipdata = array()

ZipData segment, each element of this array contains local file header plus zipped data


cdir

public var $cdir = array()

central directory array

Method Detail

ss_zip()

public void ss_zip(string zipfile = "",
                   int complevel = 6)

constructor

Parameters:
zipfile - if not empty must contain path to valid zip file, ss_zip will try to open and parse it. If this parameter is empty, the new empty zip archive is created. This parameter has no meaning in LIGHT verion, please upgrade to PROfessional version.
complevel - compression level, 1-minimal compression, 9-maximal, default is 6

clear()

public void clear()

Resets the objec, clears all the structures


open()

public void open(str zipfile,
                 bool append = false)

opens zip file.


*** This functionality is available in PRO version only. ***
please upgrade
This function opens file pointed by zipfile parameter and creates all necessary structures

Parameters:
zipfile - path to the file
append - if true the newlly opened archive will be appended to existing object structure

save()

public void save(str zipfile,
                 char where = 'f')

saves to the disc or sends zipfile to the browser.

Parameters:
zipfile - path under which to store the file on the server or file name under which the browser will receive it. If you are saving to the server, you are responsible to obtain appropriate write permissions for this operation.
where - indicates where should the file be sent
  • 'f' -- filesystem
  • 'b' -- browser
Please remember that there should not be any other output before you call this function. The only exception is that other headers may be sent. See http://php.net/header

add_data()

public void add_data(str filename,
                     str data = null)

adds data to zip file

Parameters:
filename - path under which the content of data parameter will be stored into the zip archive
data - content to be stored under name given by path parameter
See Also:
ss_zip::add_file

add_file()

public void add_file(str filename,
                     str storedasname = "")

adds a file to the archive

Parameters:
filename - contains valid path to file to be stored in the arcive.
storedasname - the path under which the file will be stored to the archive. If empty, the file will be stored under path given by filename parameter
See Also:
ss_zip::add_data

archive()

public str archive()

compile the arcive.

This function produces ZIP archive and returns it.

Returns:
string with zipfile

seek_idx()

public int seek_idx(int idx)

changes pointer to current entry.

Most likely you will always use it to 'rewind' the archive and then using read() Checks for bopundaries, so will not allow index to be set to values < 0 ro > last element

Parameters:
idx - the new index to which you want to rewind the archive curent pointer
Returns:
idx the index to which the curent pointer was actually set
See Also:
ss_zip::read

read()

public array read()

Reads an entry from the arcive which is pointed by inner index pointer.


*** This functionality is available in PRO version only. ***
please upgrade
The curent index can be changed by seek_idx() method.

Returns:
Returns associative array of the following structure
  • 'idx'=> index of the entry
  • 'name'=>full path to the entry
  • 'attr'=>integer file attribute of the entry
  • 'attrstr'=>string file attribute of the entry
    This can be:
    • 'file' if the integer attribute was 32
    • 'dir' if the integer attribute was 16 or 48
    • 'unknown' for other values
See Also:
ss_zip::seek_idx

remove()

public bool remove(int idx)

Removes entry from the archive.

please be very carefull with this function, there is no undo after you save the archive

Parameters:
idx
Returns:
true on success or false on failure

extract_data()

public array extract_data(int idx)

extracts data from the archive and return it as a string.


*** This functionality is available in PRO version only. ***
please upgrade
This function returns data identified by idx parameter.

Parameters:
idx - index of the entry
Returns:
returns associative array of the folloving structure:
  • 'file' path under which the entry is stored in the archive
  • 'data' In case if the entry was file, contain its data. For directory entry this is empty
  • 'size' size of the data
  • 'error' the error if any has happened. The bit 0 indicates incorect datasize, bit 1 indicates CRC error
See Also:
ss_zip::extract_file

extract_file()

public void extract_file(int idx,
                         string path = ".")

extracts the entry and creates it in the file system.


*** This functionality is available in PRO version only. ***
please upgrade

Parameters:
idx - Index of the entry
path - the first part of the path where the entry will be stored. So if this is '/my/server/path' and entry is arhived/file/path/file.txt then the function will attempt to store it under /my/server/path/arhived/file/path/file.txt You are responsible to ensure that you have write permissions for this operation under your operation system.

_check_idx()

private void _check_idx(var $idx)
Parameters:
$idx

_write()

private void _write(var $name,
                    var $data)
Parameters:
$name
$data

Overview  Package SS_ZIP class