ZipWriter Class
Contains methods to add zip entries, generate a zipped archive, and return the result as an Apex blob.
This sample code compresses email attachments into a single file.
The following are constructors for ZipWriter.
-
Creates a new instance of the
ZipWriterclass.
Creates a new instance of the ZipWriter class.
global ZipWriter()
The following are methods for ZipWriter.
-
Adds an entry to the zip file with the specified name and content.
-
Adds a copy of the specified prototype entry to the zip file and includes details such as the zip entry name, comment, last modification time, and content.
-
addEntry(name, comment, modTime, method, data)
Adds an entry to the zip file with the specified name, comment, last modification time, compression method, and content.
-
Compresses the zip entries and generates a ZIP archive.
-
Gets a list of all the entries in the zip file.
-
Gets the entry with the specified name from the zip file.
-
Gets a set of all the zip entry names in the zip file.
-
Gets the compression level of the zip file.
-
Gets the compression method of the zip file.
-
Removes the entry with the specified name from the zip file.
-
Sets the compression level of the zip file.
-
Sets the compression method for the zip file.
Adds an entry to the zip file with the specified name and content.
public Compression.ZipEntry addEntry(string name, blob data)
Type: Compression.ZipEntry
Zip entry added to the zip file.
Adds a copy of the specified prototype entry to the zip file and includes details such as the zip entry name, comment, last modification time, and content.
public Compression.ZipEntry addEntry(compression.ZipEntry prototype)
- prototype: Type: Compression.ZipEntry Details of the entry to be added to the zip file.
Type: Compression.ZipEntry
Adds an entry to the zip file with the specified name, comment, last modification time, compression method, and content.
public Compression.ZipEntry addEntry(String name, String comment, Datetime modTime, Compression.Method method, Blob data)
- name: Type: String The name of the zip entry.
- comment: Type: String The comment about the zip entry.
- modTime: Type: Datetime The last modification timestamp of the zip entry.
- method: Type: Compression.Method The compression method of the zip entry, which is either
DEFLATEDorSTORED. - data: Type: Blob The content of the zip entry.
Type: Compression.ZipEntry
Zip entry added to the zip file.
Compresses the zip entries and generates a ZIP archive.
public blob getArchive()
Type: blob
Apex blob that contains the bytes of the compression operation.
Gets a list of all the entries in the zip file.
public List<Compression.ZipEntry> getEntries()
Type: List<Compression.ZipEntry>
Gets the entry with the specified name from the zip file.
public compression.ZipEntry getEntry(string name)
- name: Type: string Name of the zip entry to be retrieved.
Type: Compression.ZipEntry
Gets a set of all the zip entry names in the zip file.
public Set<String> getEntryNames()
Type: Set<String>
Gets the compression level of the zip file.
public Compression.Level getLevel()
Type: Compression.Level
Uses the Level enum values to indicate the compression level as BEST_COMPRESSION, BEST_SPEED, DEFAULT_LEVEL, or NO_COMPRESSION.
Gets the compression method of the zip file.
public Compression.Method getMethod()
Type: Compression.Method
Uses the Method enum values to indicate the compression method as DEFLATED or STORED.
Removes the entry with the specified name from the zip file.
public Void removeEntry(string name)
- name: Type: string Name of the zip entry to be removed. If an entry with this name isn’t found, the method throws a
ZipExceptionexception.
Type: Void
Sets the compression level of the zip file.
public Compression.ZipWriter setLevel(compression.Level value)
- value: Type: Compression.Level Uses the
Levelenum to set the compression level.
Type: Compression.ZipWriter
Returns the zip file set with the specified compression level.
Sets the compression method for the zip file.
public Compression.ZipWriter setMethod(compression.Method value)
- value: Type: Compression.Method Uses the
Methodenum to set the compression method.
Type: Compression.ZipWriter
Returns the zip file set with the specified compression method.