^Status|Draft|
^Todo|Needs updating from library to module|
====== Archive Module ======
===== Overview =====
The Archive Module is a convenient way of constructing Archives (Zip Files, Tar Files, etc) dynamically. It can persist them to the file system, or it can send the binary file directly to the user without saving to the hard drive.
Currently it supports Zip, GZip, BZip and Tar Archives.
===== Loading the archive module =====
This can be done in the application/config/config.php file using the 'modules' setting.
$config['modules'] => array
(
MODPATH.'auth',
MODPATH.'archive'
)
Then you just have to instantiate the module to use it. For example:
$this->archive = new Archive;
4 drivers are currently available: Zip, GZip, BZip and Tar. The default one is Zip but to load another one just pass it to the constructor:
* ''zip'' - default
* ''gzip''
* ''bzip''
* ''tar''
// Load GZip driver
$this->archive = new Archive('gzip');
===== Methods =====
==== Adding a file/directory to the archive ====
''add($path, $name = NULL, $recursive = NULL)'' adds files and directories to your archive. It accepts the following parameter:
* **[string]** ''$path'' the path to the file or directory to add. Relative paths must be relative to the root website dir.
* **[string]** ''$name'' name to use for the given file or directory
* **[bool]** ''$recursive'' add files recursively, used with directories - default FALSE
This will result in file.txt being added to the archive:
$this->archive->add("files/uploads/file.txt");
==== save() ====
''save($filename)'' saves the archive you've been creating to the disk.
* **[string]** ''$filename'' path to save the archive file. Relative paths must be relative to the root website dir.
$this->archive->save("myarchive.zip");
==== download() ====
''download($filename)'' offers the archive as a download to the user.
* **[string]** ''$filename'' name to be given to the archive file
$this->archive->download("myarchive.zip");