File_Archive version 1.3 introduces some new functions to edit existing archives. These functions will allow you to remove or append files to an existing archive.
Since for File_Archive, the file system is just another reader / writer, those modifications can be done on "real" archives (real files), or on nested archives (an archive inside another archive).
Remove files from an existing archive
To remove files from an archive, you'll use one of the following functions from File_Archive class:
Removes all the files that follow a given predicate from file $URL. Note that the URL is the same as in the File_Archive::read() function. You can use nested archives.
Same as remove, but use $source instead of the default file system reader. If no URL is specified, $source must be an archive, and the files will be removed from here.
This function will remove all the doublons from the archive at $URL; only the most recent file will be kept.
If the modification date is not specified for a file, it will be considered infinitely old.
If two files have the same modification date, the one that has highest position in the archive (usually the one that was added to the archive at last) will be kept.
Same as removeDuplicate(), but use $source instead of the default file system reader. If no URL is specified, the duplicates will be removed from $source itself.
Note that those functions will not recursively uncompress archives.
Example 43-1. Remove Jpg, gif and Bmp from a zip archive
Example 43-2. Remove image files from a nested archive
Appending files to an archive
To append files to an archive, you'll use one of the following functions from File_Archive class:
Allows to append to the archive specified by the URL.
If unique is set to true, the eventual duplicates created by the insertion of new files will be automatically removed. If set to null, the default value (that you can change using File_Archive::setOption('appendRemoveDuplicates', true/false)) is used (false by default).
If the archive does not exist, it will be created using the type specified in parameter (or looking at the extension in the URL if the type is not specified), and the stat array.
appenderFromSource(&$source [, $URL = null [, $unique = null [, $type = null [, $stat = array()]]]])
Same as appender, but using $source instead of the default file system reader.
Both of these functions return a writer that you can use as in the previous examples, using the extract function
Example 43-3. Add a folder to an archive
Note that if you use a string instead of a writer in a function, the string will be converted using File_Archive::appender(). Thus the previous example could be rewritten to:
Example 43-4. Add a folder to an archive