Example Code

GZip Compression

Code and Documents

Attachment

Download All

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.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
cirrusio
Active Participant
Active Participant
on

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.

samsharp99
Member
Member
on

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.

sisthe17
Member
Member
on

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

samsharp99
Member
Member
on

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.

Siho
Member
Member
on

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?

samsharp99
Member
Member
on

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.

kinnikinnick
Member
Member
on

Thank you!

aartjan
Active Participant
Active Participant
on

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?

------------------------------------------------------------------------------------
Seriously concerned about the Labview subscription model
hollowhorse
Member
Member
on

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.