Extracting files with jszip and saving to local disk using npapi-file-io. Binary file save very slow

StackOverflow https://stackoverflow.com/questions/16431945

  •  14-04-2022
  •  | 
  •  

Question

I'm using JSZip to open a zip file. Looping and saving each file as a binary file using the npapi-file-io plugin. The problem is; it's very slow. Extracting a zip locally takes a couple of minutes even for a 2mb zip file. If I save the files as text files it's very fast. But they must be saved as binary or they become corrupt. Any ideas? Please tell me I'm doing this wrong or the hard way.

//read contents of zip file
var zip = new JSZip(e.target.result);
$.each(zip.files, function (index, zipEntry) {
    var filename = zipEntry.name;
    //create directory else create file
    var path = getPath(filename);
    if (filename.match(/\/$/)) {
        //plugin is the embeded npapi-file-io plugin
        plugin.createDirectory(path);
    } else {
        //problem is here
        plugin.saveBinaryFile(path, zipEntry.asUint8Array());
        //this is faster and works with the txt files but not images ect.
        //plugin.saveTextFile(path, zipEntry.data);
    }
Was it helpful?

Solution

There is no performant way to send binary data to a plugin; basically to send something using a uint8array will always be very slow because of how npapi works, so you'd be better off if you could send it base64 encoded. What it comes down to is that the only way to really do this in a performant way is likely to create your own plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top