why the compression ration is 0 using JSZip
Asked Answered
S

1

8

I converted my downloadable xml file to zip using the following code but the file size is sill same and the compression ratio shows 0%

    var xmlcontent = "<?xml version='1.0' encoding='UTF-8'?><Body>";
    xmlcontent += json2xml(data);
    xmlcontent += "</Body>";

    var zip = new JSZip();
    zip.file("test1.xml", xmlcontent);
    zip.generateAsync({ type: "blob" })
    .then(function (content) {

        var a = document.createElement("a");
        document.body.appendChild(a);
        a.style = "display: none";
        var url = window.URL.createObjectURL(content);
        a.href = url;
        a.download = "test.zip";
        a.click();
        window.URL.revokeObjectURL(url);

    });

The reason of compression was to decrease the size of the file the client retrieves but apparently it had no effect on it. Kindly suggest a way to decrease the file size.

Spireme answered 12/1, 2017 at 13:16 Comment(1)
Thanks got it. it is now working perfectly. You can put it as answer :)Kapor
M
11

The default compression setting for file(s) is STORE (= no compression) - as stated in the documentation

Change it to DEFLATE with the options parameter of .generateAsync(options)

var zip = new JSZip();
zip.file("test1.xml", xmlcontent);
zip.generateAsync({
        type: "blob",
        compression: "DEFLATE"
    })
    .then(function (content) {
            ...
    });
Mateya answered 12/1, 2017 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.