Create a zip file

Added by iNTERFACEWARE

How to create and unzip a zip file containing multiple files and directories, using filter.zip.deflate() and filter.zip.inflate()

Source Code
   -- create a zip file for the "test_zip" directory
   -- containing two files "a-test" and "b-test"

   -- construct hard-coded table to zip
   local  T = {['test_zip']={['a-test.txt']='a', ['b-test.txt']='b'}}
   trace(T)
   
   -- zip the file into a string
   local zip = filter.zip.deflate(T)
   trace(zip)
   
   -- unzip the file from the string
   local unzip = filter.zip.inflate(zip)
   trace(unzip)
   
   -- save the file to disk 
   local f = io.open('test_zip.zip', 'w')
   f:write(zip)
   f:close()
   
   -- go to the Iguana home directory and run 'test_zip.zip'
   -- NOTE: If you change the contents of the files "a-test" and "b-test"
   --       they will be reflected in the new zip file created 
   
   -- create the zip file using content from the test_zip directory
   
   -- open the files
   local fa = io.open('test_zip/a-test.txt', 'r')
   local fb = io.open('test_zip/b-test.txt', 'r')

   -- construct table to zip using file content
   -- NOTE: We also added an (empty) subdirectory 'test_sub'
   local  TT = {['test_zip2']={['a-test.txt']=fa:read(), ['b-test.txt']=fb:read(),['test_sub']={}}}
   trace(TT)

   -- zip the file into a string
   local zip = filter.zip.deflate(TT)
   trace(zip)
   
   -- unzip the file from the string
   local unzip = filter.zip.inflate(zip)
   trace(unzip)

   -- save the second zip file to disk 
   local f = io.open('test_zip2.zip', 'w')
   f:write(zip)
   f:close()
   
   -- go to the Iguana home directory and run 'test_zip2.zip'
   -- view the directory contents to confirm the 'test_sub' subdirectory was created
Description
How to create and unzip a zip file containing multiple files and directories, using filter.zip.deflate() and filter.zip.inflate()