Flexible Brotli Compression Library For Your Windows Delphi/C++ Builder VCL And FMX Apps
Most of Delphi and C++ Builder developers utilize preinstalled components and libraries to compress and decompress files. For instance, the System.Zlib which supports gzip and deflate, the System.Zip is also helpful to handle .zip archive files. Moreover, Indy’s TIdCompressorZLib which is based on Zlib.
But that is not it. There are more different libraries based on different compression algorithms and more modern techniques, for instance, the Brotli – Brotli is similar in speed with deflate but offers more impenetrable compression. Brotli is open-sourced under the MIT License by Google. Brotli compressed files have .br extension.
To connect your Delphi or C++ Builder VCL and FMX application with the Brotli library we can rely on Brotli Compress library from WINSOFT which offers to use the Brotli library easily.
Brotli itself is free to use and distribute, but the Brotli Compress by WINSOFT is a commercial library and if you would like to use that library you should get a license!
- Uses Brotli library
- Supports Windows 32 and Windows 64
- Available for Delphi/C++ Builder 6 – 10.4
After downloading the Brotli from WINSOFT you should configure the library into your RAD Studio. You can follow the tutorial here that shows the steps to configure without errors.
Since the Brotli itself is a whole compression library your application should have brotlilib.dll – Dynamic-link library. You will get those files within the Brotli Compressor by WINSOFT in a Library Folder.
Brotli Compressor Library has two main classes:
- TBrotliEncoder
- TBrotliDecoder
As you can observe the TBrotliEncoder encodes and TBrotliDecoder decodes the files with the given parameters. Furthermore, the OnProgress event provides the decompression and compression progress info.
Additionally, you can set encoding quality with the Quality property.
Here is the Brotli library demonstration video that shows the demo application in action.
These are demo projects’ UI:
This is how you can encode with Brotli:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
InputStream := TFileStream.Create(EditFileName.Text, 0); try OutputStream := TFileStream.Create(ChangeFileExt(EditFileName.Text, ‘.br’), fmCreate); try with TBrotliEncoder.Create do try if RadioButtonGeneric.IsChecked then Mode := emGeneric else if RadioButtonText.IsChecked then Mode := emText else Mode := emFont; Quality := Round(TrackBarQuality.Value); OnProgress := Self.OnProgress; Compress(InputStream, OutputStream); finally Free; end; finally OutputStream.Free; end; finally InputStream.Free; end; |
Here is how you can decode with the Brotli:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
InputStream := TFileStream.Create(EditFileName.Text, 0); try if CheckBoxCheckIntegrity.IsChecked then OutputStream := nil else OutputStream := TFileStream.Create(ChangeFileExt(EditFileName.Text, ‘.uncompressed’), fmCreate); try with TBrotliDecoder.Create do try OnProgress := Self.OnProgress; Decompress(InputStream, OutputStream); finally Free; end; finally OutputStream.Free; end; finally InputStream.Free; end; |
As you can see this is uncomplicated and you just need to implement the file selection process and input/output streams.
Head over and check out the full WINSOFT Brotli Compression Library!