中文页 | English
FastLZ is a fast and lossless compression library that contains only two files, is simple to use and easy to integrate. This FastLZ library is a port of RT-thread to the official FastLZ C library. For more information about fastlz, please refer to http://fastlz.org/index.html.
- Use menuconfig
RT-Thread online packages --->
miscellaneous packages --->
[*] Fastlz: A portable real-time compression library
- Configure the enable sample option
Enable using fastlz sample
; - Configure the compression level option, set to level 1 (there are two levels 1 or 2, level 1 has the fastest compression speed, and level 2 has a large compression ratio);
- The configuration package version is selected as the latest version
latest_version
.
This example is a simple file compression and decompression routine, which depends on the file system. The commands used are two -c
and -d
. The -c
command compresses one file to another, The -d
command decompresses a file to another file.
How to use:
msh cmd compression: fastlz_test -c /file.bin /file.cmprs.bin
msh cmd decompression: fastlz_test -d /file.cmprs.bin /file_dcmprs.bin
msh />fastlz_test -c /file.bin /file.cmprs.bin
[fastlz]compress start: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>
[fastlz]compressed 469848 bytes into 363495 bytes, compression ratio is 77%!
msh />
msh />fastlz_test -d /file.cmprs.bin /file_dcmprs.bin
[fastlz]decompress start: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>
[fastlz]decompressed 363495 bytes into 469848 bytes!
The FastLZ source code uses static memory allocation. A 32Kbytes buffer is preset, which occupies too much stack resources. The source code is modified and dynamic memory allocation is used to replace the original static memory allocation.
Make the following changes to the source code fastlz.c
, you need to pay attention when porting the official code:
- Add dynamic memory allocation definition
#include <rtthread.h>
#define malloc rt_malloc
#define free rt_free
- Use
malloc
to allocate memory forhtab
const flzuint8* htab[HASH_SIZE];
Replace with
const flzuint8** htab = (const flzuint8**)malloc(sizeof(flzuint8*) * HASH_SIZE);
- Use
free
to release memory beforereturn
- FastLZ official website: http://fastlz.org/index.html