Whenever we exchange files, we always go through the ritual of compressing the files before sending them. Since 4D v18, two commands are available, allowing you to create and read a ZIP archive using the standard zip compression algorithm.
With 4D V19 R3, the Zip Create Archive command supports a new compression algorithm: LZMA. The advantage of this algorithm is that it creates smaller archives than the standard zip compression algorithm. Let’s find out more!
What Is LZMA?
LZMA is the acronym for Lempel-Ziv-Markov chain algorithm. LMZA is a lossless compression algorithm created by Igor Pavlov. This data compression algorithm uses a dictionary compression scheme similar to the LZ77 algorithm published by Abraham Lempel and Jacob Ziv.
How to use it?
You can pass a “zipArchive” object to the ZIP Create Archive command to customize your zip. This allows you to choose the compression algorithm, the encryption algorithm, and some other options. Read the documentation for more details.
For the compression algorithm, you can set the “compression” attribute to:
- ZIP Compression None
- ZIP Compression Standard
- ZIP Compression LZMA
- ZIP Compression XZ
For the compression level, you can set the “level” attribute between 1 to 10.
Here is an example that compresses a folder using the LZMA algorithm:
var $zip; $status : Object
var $destination : 4D.File
$zip.files.push(Folder(fk documents folder).folder("Archive 2020"))
$zip.compression:=ZIP Compression LZMA
$destination:=Folder(fk desktop folder).file("Archive2020.zip")
$status:=ZIP Create archive($zip; $destination)
Here is the result obtained on an archive of almost 2GB containing 1800 images:
Back to you! Do not hesitate to share your feedback and impressions on the forum.