LZF Compression library to compress data
1 Overview
3 Methods
4 Usage
6 See also
The LZF Compression component is a useful extension to Unity to be able to compress data for sending over a network or for more efficient saving.
The library is complete and has even been patched a few times already through the forum thread, so I took the most stable version without issues. (issus were reported on other versions, so I didn’t take them)
There are some Unit Tests included in the following file:
Assets\unity-ui-extensions\Scripts\Editor\CompressionTests.cs
These details some sample use cases and also provide a good way to test that the compression/decompression works as expected. To run these Unit Tests In Unity 5.3, open the following editor window from the menu to see the tests and run them.
Window\Editor Tests Runner
(For earlier versions of Unity, you will need to install the “Unity Test Tools” asset from the store and follow the instructions from there.)
Simply create a byte array in code for the data you want compressed and pas it to the Compress function of the Library, as follows:
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
To decompress, follow the same process using the Decompress function and then unencode your data as follows:
var decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
For more examples, see the Unit Tests included in the following file:
Assets\unity-ui-extensions\Scripts\Editor\CompressionTests.cs
N/A
N/A
Roman Atachiants kelindar@gmail.com Oren J. Maurice oymaurice@hazorea.org.il Marc Alexander Lehmann schmorp@schmorp.de