Javascript to create a zip file

I have an ionic app in which I need to create zip of some files on the device and send them to node server.

I am trying to use JSZip [http://stuk.github.io/jszip/] to create a zip of the files on the device. I have complete path of each of the files which is send to the function in filesList array.

In the service

// complete path of all the files that need to be zipped is in filesList array
// Eg., file:///var/mobile/Containers/Data/Application/BACCA40A-56C4-4BE5-8C5D-1576960BD14B/Library/NoCloud/1473447800255.zip
  var zipFiles = function(filesList) {
            var uniqueFilename = Date.now();
            var zip = new JSZip();
            // create a zip with a unique name
            var zipFolder = zip.folder(uniqueFilename);
            //add files to the zip
            filesList.forEach(function(file) {
               zipFolder.file(file);    
            })
            return zipFolder;         
   }     

In the controller

myAPI.zipFiles(docList)
               .then(function(result) {
                   console.log('Zip created '+JSON.stringify(result)); 
               .catch(function(error) {
                 console.log('Error while creating zip '+error);
               });

I would like to create a zip in memory (don’t need to save it on the device) and send it to node.

The code above is resulting in an empty zip even though filesList array has 5 files and the path to those files is also valid.

Can someone please help me in getting this correct or is there an alternate library that I should be using.

Since the server is under your control, here’s my suggestion:

https://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

Thank you for the response. I believe, my use case is different.

User would have some files on the device - text files that they created, pictures that they clicked, PDFs that were donwloaded etc.

On click of a button, the app needs to send these files to the server. Instead of sending multiple files to the server, I was planning to zip them into one zip file and send it over. With this either everything goes or everything fails. We won’t end up in a situation where some files got uploaded and others failed due to some issue.

Hi ank5,

You should still be able to use a simple solution such as GZip’ing your transmission stream. Look into https://www.npmjs.com/package/gzip-stream