Skip to main content

Code reviews rule: Use native ZIP functions over Zippex

Written by David Martin
Updated this week

Use native ZIP functions over Zippex

Why is this an issue?

Zippex is a commonly used third-party Apex ZIP library, but it has significant limitations:

  • No DEFLATE compression: Zippex doesn't implement DEFLATE, so data is not actually compressed

  • CPU intensive: Large files can consume excessive CPU time, risking governor limits

  • Native alternative available: Salesforce provides built-in compression functions

Examples

Example of incorrect code:

// Using Zippex library
Zippex archive = new Zippex();
archive.addFile('data.txt', Blob.valueOf(largeData), null);
Blob zipData = archive.getZipArchive();

Example of correct code:

// Writing a ZIP archive with native Compression.ZipWriter
Compression.ZipWriter writer = new Compression.ZipWriter();
writer.addEntry('data.txt', Blob.valueOf(largeData));
Blob zipData = writer.getArchive();

// Reading a ZIP archive with native Compression.ZipReader
Compression.ZipReader reader = new Compression.ZipReader(zipData);
for (Compression.ZipEntry entry : reader.getEntries()) {
Blob extracted = reader.extract(entry.getName());
}

How can I fix violations?

  1. Use Compression namespace: Replace Zippex with Compression.ZipWriter and Compression.ZipReader for ZIP archive operations, or Compression.compress()/Compression.decompress() for simple single-blob compression.

  2. Remove Zippex dependency: Delete the third-party library after migration.

When should I disable this rule?

You may dismiss specific violations if you rely on Zippex-specific behavior that cannot be replicated with the native Compression namespace.

Resources

Did this answer your question?