<cfzip>

Manipulates ZIP and Java Archive (JAR) files.

In addition to the basic zip and unzip functions, use the cfzip tag supports

  • deleting entries from an archive
  • filter files
  • read files in binary format
  • list the contents of an archive
  • specify an entry path used in an executable JAR file.

This tag may have a body.

This tag is also supported within <cfscript>

Requires Extension: Compress Tags

<cfzip action=delete|list|read|readbinary|unzip|zip password=string charset=string destination=string entrypath=string file=string filter=any filterdelimiters=string name=string overwrite=boolean prefix=string recurse=boolean showdirectory=boolean source=string storepath=boolean variable=string encryptionalgorithm=string compressionmethod=string ><!--- body --->[</cfzip>]
Attribute Description Default
action
string, optional

The action to take.

  • delete
  • list
  • read
  • readbinary
  • unzip
  • zip

zip

password
string, optional

Password for the zip file.

charset
string, optional

The character set used to translate the ZIP or JAR entry into a text string.

Examples of character sets are:

  • JIS
  • RFC1345
  • UTF-16 (optional, default=encoding of the host machine)
destination
string, optional

Destination directory where the ZIP or JAR file is extracted.

entrypath
string, optional

Pathname on which the action is performed.

file
string, optional

Absolute pathname of the file on which the action is performed.

For example, the full pathname of the ZIP file: c:\temp\log.zip.

filter
any, optional

Optional filter.

  • Can be either a wildcard filter, e.g. "m*"
  • or a UDF/Closure which is passed each file/directory path and returns a boolean value to indicate whether that item should be included in the result or not.

function ( entryPath ){ return true | false }

filterdelimiters
string, optional

Optional when passing a filter pattern. This value is used as a delimiter for the patterns. Default is the pipe "|" character.

name
string, optional

Record set name in which the result of the list action is stored. The record set columns are:

  • name: filename of the entry in the JAR file. For example, if the entry is help/docs/index.htm, the name is index.htm.
  • directory: directory containing the entry. For the example above, the directory is help/docs. You can obtain the full entry name by concatenating directory and name. If an entry is at the root level, the directory is empty ('').
  • size: uncompressed size of the entry, in bytes.
  • compressedSize: compressed size of the entry, in bytes.
  • type: type of entry (directory or file).
  • dateLastModified: last modified date of the entry, cfdate object.
  • comment: any comment, if present, for the entry.
  • crc: crc-32 checksum of the uncompressed entry data.
overwrite
boolean, optional

unzip: Specifies whether to overwrite the extracted files:

  • yes: if the extracted file already exists at the destination specified, the file is overwritten.
  • no: if the extracted file already exists at the destination specified, the file is not overwritten and that entry is not extracted. The remaining entries are extracted.

zip: Specifies whether to overwrite the contents of a ZIP or JAR file:

  • yes: overwrites all of the content in the ZIP or JAR file if it exists.
  • no: updates existing entries and adds new entries to the ZIP or JAR file if it exists. (optional, default=no)
prefix
string, optional

String added as a prefix to the ZIP or JAR entry. The string is the name of a subdirectory in which the entries are added.

recurse
boolean, optional

Specifies whether the action applies to subdirectories:

  • yes: includes subdirectories.
  • no: does not include subdirectories. (optional, default=yes)
showdirectory
boolean, optional

yes: lists the directories.

no: does not list directories. (optional, default= no)

source
string, optional

Source directory to be zipped. Not required if cfzipparam is specified.

storepath
boolean, optional

zip: Specifies whether pathnames are stored in the ZIP or JAR file:

  • yes: pathnames of entries are stored in the ZIP or JAR file.
  • no: pathnames of the entries are not stored in the ZIP or JAR file. All the files are placed at the root level. In case of a name conflict, the last file in the iteration is added.

unzip: Specifies whether files are stored at the entrypath:

  • yes: the files are extracted to the entrypath.
  • no: the entrypath is ignored and all the files are extracted at the root level. (optional, default= yes)
variable
string, optional

Variable in which the read content is stored.

encryptionalgorithm
string, optional

Supported algorithms are:

  • aes(=aes256)
  • aes128
  • standard
compressionmethod
string, optional

Set the zip compression level

  • deflate,deflateNormal (default)
  • deflateFast
  • deflateFastest
  • deflateMaximum
  • deflateUtra
  • aesenc
  • store (no compression, good for images)

Examples

Simple format for cfzip

Action unzip

<cfzip action="unzip" destination="#gettempdirectory()#" file="zippath">

Action delete

<cfzip action="delete" file="#expandpath('./list.zip')#" entrypath="list/hai">

Action zip

<cfzip action="zip" source="#expandpath('./ziptest.txt')#" file="#expandpath("'./zip/')#">

Action list

<cfzip action="list" file="#expandpath('./list.zip')#" name="res">

See also