The code below shows how you can create a zip archive after being passed a number of files to compress. This is useful for both bundling files together and creating smaller file sizes.

The basics of it are to create the initial zip file then cycle through each file and add it to the archive using a zip writer, being sure to specify the deflate method to get better compression.

Also, try this code if you are unzipping files.

Initially based on this code . There’s also the docs for archive/zip .