Create a bzip2 or gzip file

Verified
Added by iNTERFACEWARE

How to create and unzip a bzip2 or gzip file, using filter.bzip2.deflate() and filter.bzip2.inflate() or gzip.deflate() and gzip.inflate()

Source Code
   -- create a bzip2 file from a string

   -- construct a test string to be compressed
   local  S = 'Replace this string with your own data, or read it in from a file'
   trace(S)
   
   -- gzip the file into a string
   local zip = filter.bzip2.deflate(S)
   trace(zip)
   
   -- unzip the file from the string
   local unzip = filter.bzip2.inflate(zip)
   trace(unzip)
   
   -- save the file to disk 
   local f = io.open('test_bzip2.zip', 'w')
   f:write(zip)
   f:close()
   
   -- go to the Iguana home directory and run 'test_bzip2.zip'
   
   -- create a gzip file from a string
   
   -- gzip the file into a string
   local zip = filter.gzip.deflate(S)
   trace(zip)
   
   -- unzip the file from the string
   local unzip = filter.gzip.inflate(zip)
   trace(unzip)
   
   -- save the file to disk 
   local f = io.open('test_gzip.zip', 'w')
   f:write(zip)
   f:close()
   
   -- go to the Iguana home directory and run 'test_gzip.zip'
Description
How to create and unzip a bzip2 or gzip file, using filter.bzip2.deflate() and filter.bzip2.inflate() or gzip.deflate() and gzip.inflate()
Usage Details

Demonstrates how to convert the contents of an Iguana table into a bzip2 or gzip file, using filter.bzip2.deflate() or  filter.gzip.deflate(). It also shows how to unzip the file using filter.bzip2.inflate() or  filter.gzip.inflate().

How to use the snippet:

  • Paste the code into your script
  • Inspect the annotations to see how it works
  • Unzip the test_bzip2.zip file that is created in the Iguana install directory
  • Unzip the test_gzip.zip file that is created in the Iguana install directory