Newer Version Available
ZIP Support
Take advantage of a native Apex Zip library to create and extract ZIP archive files
by using the class methods in the Compression namespace.
You can compress multiple attachments or documents into an Apex blob that contains the ZIP archive. You can also specify the data to be extracted from the zip archive, without uncompressing the entire ZIP archive. To optimize compression, you can specify a compression method and compression level.
This example code extracts a JSON translation file from a callout response containing a ZIP archive by getting and extracting the specified entry from the ZIP archive.
1HttpRequest request = new HttpRequest();
2request.setEndpoint('callout:My_Named_Credential/translationService');
3request.setMethod('POST');
4// Set request payload to translate...
5
6HttpResponse response = new Http().send(request);
7Blob translationZip = response.getBodyAsBlob();
8
9ZipReader reader = new ZipReader(translationZip);
10ZipEntry frTranslation = reader.getEntry('translations/fr.json');
11Blob frTranslationData = reader.extractEntry(frTranslation);
12