Javascript add existing zip file to generated zip JSZip

368
May 01, 2017, at 06:10 AM

I'm trying to add an existing zip archive contents to the archive that is being generated using JSZip. I'm also using JSZipUtils.js to get binary contents from URL and a FileSaver.js to save a generated archive. Here is a very basic code made out of examples from the docs:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>   
   <script type="text/javascript" src="./js/jszip.js"></script>
    <script type="text/javascript" src="./js/jszip-utils.js"></script>
    <script type="text/javascript" src="./js/FileSaver.js"></script>
Downloading archive with contents from another archive
<script>
jQuery(function($) {

        var zip = new JSZip();
        zip.file("example.txt", "salute");
        JSZipUtils.getBinaryContent("./make/version.zip", function (err, data) {
           if(err) {
              throw err; // or handle the error
           }
           var zip = new JSZip();
           zip.loadAsync(data);
        });
        // when everything has been downloaded, we can trigger the dl
        zip.generateAsync({type: 'blob'},
            function(metadata) {
            })
            .then(function(blob) {
                // see FileSaver.js
                saveAs(blob, 'config.zip');
            }, function(e) {
                showError(e);
            });
        return false;
});
</script>

The zip file I'm trying to load is being stored on the same server. I didn't have any issues with JSZip.file(), it loads any binaries and includes them to the archive.

Everything works just fine, it makes and downloads an archive, but it completely ignores the contents of the zip file I'm trying to include. Maybe I do not understand documentation on JSZip.loadAsync() or something, but it looks fine in my code for me. Please help.

READ ALSO
Error in displaying sweet alert dialog

Error in displaying sweet alert dialog

I'm trying to make an alert using the Sweet Alert libraryI have tried to integrate the code for making a confirmation alert for deleting an item, but when I click on the button for deleting the item these not work

274
Not sure how to properly execute resize function update

Not sure how to properly execute resize function update

Trying to add a resize function to this that allows for the if else statement on the bottom of this script to update based on window width with a refresh and with resize as wellEverything is working properly except when the down arrow button on the hero is clicked...

324
How to make codiad editor to be able to show &#39;autocomplete suggest&#39; code everytime I input something in Editor (Without using Ctrl+Space)

How to make codiad editor to be able to show 'autocomplete suggest' code everytime I input something in Editor (Without using Ctrl+Space)

I know Codiad uses ace editor, how can I implement this (below) Javascript of ace editor in codiad:

242