tmt_zip

tmt_zip

tmt_zip

A stateless CFC that support different kind of tasks related to zip files. The main goal here is making the code easy to read/understand/maintain and, more in general, provide a rich set of APIs. Performances optimisation was not considered a top priority. This component requires having tmt_file_io.cfc located inside the same directory since it use it internally for file I/O tasks. Special thanks to Nathan Dintenfass for pioneering a few techniques used here. ColdFusion 6.1 or above required

Metadata

addToZipStream()

Add a file to a given Java java.util.zip.ZipOutputStream object (remember to close the zip stream after calling this method!)

Arguments

Name Type Required Default Options Description
fileSourcePath string Yes Absolute file path
pathFromZipBase string Yes Destination path for the file, relative to the zip root
zipStream String Yes Java java.util.zip.ZipOutputStream object

entryExists()

Check if a file/directory is contained inside a given zip file

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file
filePath string Yes File path, it must be relative to the zip root

extractJavaEntry()

Extract a single Java entry object to a destination directory

Arguments

Name Type Required Default Options Description
jZip String Yes Java zip object
jZipEntry String Yes Java entry object
destination string Yes Absolute path of a directory where the contents will be extracted

getEntryInfo()

Return a structure containing information about an entry inside a given zip file

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file
filePath string Yes File path, it must be relative to the zip root

getEntryList()

Get a directory listing from a given zip file

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file

getEntryPaths()

Get an array of file and directory paths contained inside a given zip file

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file

getJavaEntries()

Extract a collection of Java entry objects from a given zip file path

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file

getJavaEntry()

Extract a single Java entry object from a given zip file path

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file
filePath string Yes File path, it must be relative to the zip root

init()

Pseudo-constructor, it ensure settings are properly loaded inside the CFC. There is no need to call it, since the CFC is stateless, but it can be handy if you want to set a compression level other than the default

Arguments

Name Type Required Default Options Description
compressionLevel numeric No [runtime expression] Compression level used by the current instance of the CFC (an integer between 0 and 9). Default to 9

unZip()

Extract all the contents from a given zip file

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file
destination string No [runtime expression] Absolute path of a directory where the contents will be extracted. Default to the directory where the zip file is located

unZipEntry()

Extract a single file/directory entry from a given zip file

Arguments

Name Type Required Default Options Description
zipFilePath string Yes Absolute file path of the zip file
filePath string Yes File path, it must be relative to the zip root
destination string No [runtime expression] Absolute path of a directory where the contents will be extracted. Default to the directory where the zip file is located

urlToJavaZip()

Turn a file path into a java.util.zip.ZipFile object

Arguments

Name Type Required Default Options Description
filePath string Yes File path

urlToZipOutput()

Turn a file path into a java.util.zip.ZipOutputStream object

Arguments

Name Type Required Default Options Description
filePath string Yes File path

zip()

Zip a single file or an entire directory

Arguments

Name Type Required Default Options Description
path string Yes Abstract pathname (file or directory)
destination string Yes Absolute file path of the newly created zip file

zipAll()

Zip a set of files

Arguments

Name Type Required Default Options Description
filesArray array Yes Array of file paths
destination string Yes Absolute file path of the newly created zip file

zipDirectory()

Zip an entire directory and its contents

Arguments

Name Type Required Default Options Description
directoryPath string Yes Absolute directory path
destination string Yes Absolute file path of the newly created zip file

zipFile()

Zip a single file

Arguments

Name Type Required Default Options Description
filePath string Yes Absolute file path
destination string Yes Absolute file path of the newly created zip file