Decompressing LZF Notes: Apple's vCard Export in MacOSX 10.8.2
When exporting contacts from the Contacts application in MacOSX 10.8.2, Apple uses the LZF compression algorithm for notes fields in vCard files. This article will help you understand what this means and how to decompress these notes.
What is LZF Compression and why does Apple use it?
LZF, or Lempel-Ziv-Fiala-Odersky, is a lossless data compression algorithm. Apple uses this algorithm in MacOSX 10.8.2 to compress notes fields in vCard files. The primary objective is to reduce data size and improve synchronization and transmission performance between devices.
Exporting vCards and the Compressed Notes Field
To export vCards from the Contacts application, follow these steps:
- Open the Contacts application.
- Select one or multiple contacts and right-click on them.
- Choose "Export vCard" from the context menu.
- Save the vCard file with the .vcf extension.
Upon inspecting the exported vCard file (e.g., with a text editor), you can find the compressed LZF notes data field in the following format:
NOTE;ENCODING=b: ...How to Decompress the LZF Notes
To decompress the LZF notes field, you can either use the command line or integrate the solution into an application. This section presents both options.
Command Line Solution
-
First, install Java Development Kit (JDK) 7 or higher because the official Java LZF implementation is not backward compatible:
$ java -version -
Next, download the LZF library from the official Maven repository:
$ wget http://search.maven.org/remotecontent?filepath=net/jpountz/lzf/1.0.1/lzf-1.0.1.jar -
After that, create a Java program to decompress the LZF-compressed notes data:
import net.jpountz.lz4.LZ4BlockDecoder; public class DecompressLZF { public static void main(String[] args) throws Exception { byte[] compressed = // your LZF-compressed data; LZ4BlockDecoder decoder = new LZ4BlockDecoder(); byte[] decompressed = new byte[4096]; int offset = 0; int length = 0; while (true) { length = decoder.decompress(compressed, offset, decompressed); if (length >= 0) { // Write the decompressed data to a file or // handle it according to your needs. offset += length; } else { break; } } } } -
Finally, compile the Java program and execute the class:
$ javac DecompressLZF.java
$ java -cp .:lzf-1.0.1.jar DecompressLZF
Integrating the Solution into an Application
To integrate the LZF decompression solution into your application, follow these steps:
-
Add the LZF library into your application's dependencies, based on your platform, for example:
- Gradle:
dependencies { compile 'net.jpountz:lz4:1.0.1' } -
Implement the LZF decompression logic in your code. For example, if you use Python:
import lz4.block def decompress_lzf(data): decoder = lz4.block.Decompressor() decompressed_data = bytearray() offset = 0 while True: try: decompressed_block = decoder.decompress(data, offset) decompressed_data += decompressed_block except (EOFError, lz4.block.FrameError): break offset += len(data) - decoder.total_in return bytes(decompressed_data)
We have learned about the LZF data compression algorithm and discovered Apple's use of this algorithm in the notes field when exporting vCard files from the Contacts application in MacOSX 10.8.2. We provided a command line solution and guidance for integrating a decompression mechanism into your application using LZF libraries.