Example Program Drafts

cancel
Showing results for 
Search instead for 
Did you mean: 

GZip Compression

GZip is a commonly used compression algorithm for compressing/decompressing strings e.g. to transfer over a network. There is no native function in LabVIEW that supports GZip compression and as I'm working on RT, the .NET solution found here is not suitable.

 

The GZip file format itself contains a header, a DEFLATE compressed body and a footer containing a CRC32 checksum and length data.

 

The DEFLATE and CRC32 checksum calculation is done by the OpenG Zip Tools. For full RT support (e.g. Linux RT), you need to use a newer version of the library than (4.1.0-b2) which can be found here. Thanks rolfk!

 

GZip Compress

GZip Compress.png

 

GZip Decompress

GZip Decompress.png

 

Updates

20/01/2016: Changed compress VI to remove the last 4 bytes of the DEFLATE output - it didn't seem to be necessary and was causing errors parsing the compressed data in Java. Downgraded the error 42 out to a warning as it seems to be always generated in the Decompress VI - I didn't delve into the ZLIB INFLATE source to figure out why.

Comments
Active Participant cirrusio
Active Participant

This is...awesome...if it works.  Going to give it a go in the next few days.

Still don't understand why NI has not implemented something for RT yet.

Member samsharp99
Member

I found a small bug that was causing the compression algorithm not to get decompressed correctly by an external library - I had to remove the last 5/6 bytes from the DEFLATE output. I'll post an updated version over the weekend.

Other than that, I've been using it fine on windows/RT (vxworks) targets for sending/receiving GZip compressed data.

Member sisthe17
Member

Where can I download the subVI of ZLIB Deflate_ogtk.vi? I encountered error on the one I downloaded. Thank you in advance.

Member samsharp99
Member

Did you follow the link in the third paragraph to the download of the OpenG Zip Tools library? If you have issues with the library then I suggest you take it up over on the LAVA forums.

Member Siho
Member

Whenever I try to decompress the while string I run out of memory, which seems strange as the string is only about some about 1 MB long. Do I need to work on parts of the string? I see there is a calculation for the compression and the meory allocated to the containing memory. How can this be so large for such a small stream?

Member samsharp99
Member

My VI doesn't really do any more than use the OpenG VIs for Deflate/Inflate/CRC calculation - I suspect that the problem is with those VIs so I can't really help with that -  I've only tried it with relatively short strings. I suggest you report your problem on the Lava forums for the Open G Zip Tools (linked above). Try to post more information - a VI and some sample data with demonstrates the problem.

Member kinnikinnick
Member

Thank you!

Active Participant aartjan
Active Participant

I am looking to uncompress gzip data from a webservice. As a test I used 7zip to create a gz compresssed file. Unfortunately I am unable to uncompress that file. If I use the GZIP compress.vi it works fine.

Apparently the gzip created with 7zip is not compatible with the code above. Any suggestions?

Member hollowhorse
Member

Nice work. I was looking for a way to compress data in memory and this was perfect.

 

However, I notice there is an error trap in the GZip Decompress VI for Error 42. The error is occuring because the expected string length is incorrect.