A Particle library to compress files on an SDCard using the Heatshrink compression technique. This compression is fast and uses a low amount of RAM.
Connect an SDcard to your Particle device. Setup the right pins and SD card configuration in the example and run it by compiling and flashing the files to a particle device. Connect to the particle using a terminal/serial monitor and let it do its magic.
See the examples folder for more details.
After sending the file.startCompress command, call file.task until the compressFile.getState()==COMPRESS_DONE, this indicates that the file is compressed. The task will request chunks of 512 bytes from the SD card and compress those. So the function is kinda non-blocking and can be used in cooperative multitasking environments.
After compressing a file, it can be decompressed on a linux or windows machine using the Heatshrink program. Use the Linux version already build in the bin folder or clone the Heatshrink repository and run make to create a binary that can be run. On a linux computer, after the binary is created, you can use "heatshrink -d -w 10 -l 4 $compressedname $name" to decompress your file. I recommend placing the heatshrink file in /usr/local/bin so you can use it everywhere on the command line.
On the Heatshrink blog a good description and overview of the different settings in the heatshrink_config.h are given. The HS 1,4 compression that is the standard setting gives a compression of about 50%.
This library is used by the FTP file send library I also created to send the compressed file over FTP to an ftp server. This library will be uploaded as soon as this one is done.
There is no option to uncompress files for now on the particle device. It might be nice to add this functionality as well. Furthermore, all space allocation is static for now, about 2k of RAM space is used. This can probably be improved by dynamic allocation.
Copyright 2017 wvdv2002
Licensed under the ISC license