how to extract the Zip file in client system using javascript

前提是你 提交于 2019-12-13 14:25:25

问题


I have a Zip file in server.i am downloading the zip file save into client system.now i want to extract file using javascript. anybody please help me. thanks in advance.


回答1:


You can unzip zipfiles in memory, within a browser, using Javascript.

This answer shows how.

The js code in the browser looks like this:

var doneReading = function(zip){
    DoSomethingWithEntries(zip);
};

var zipFile = new ZipFile(url, doneReading); 

Inside the DoSomethingWithEntries method, which you provide, you can fiddle with an object that represents the extracted zip file.

function DoSomethingWithEntries(zip){ 
  // for each entry in the zip...
  for (var i=0; i<zip.entries.length; i++) {
    var entry = zip.entries[i];
    var entryInfo = "<h4><a>" + entry.name + "</a></h4>\n<div>";  
    // put that into a div, if you like.
    // etc...
  }
}

As shown above, you can emit lists of the entries with their name, size, date, and so on.

You can also call an extract() method on each zip entry. (not shown here) If you extract, the extraction happens asynchronously. The content gets expanded into byte arrays or strings (depending on whether the entries are binary or text) that are maintained in the memory of the browser javascript environment. You could then display the extracted content from the zipped entries, or whatever you like.

I don't believe you can interact with the filesystem, either reading or writing, unless you resort to something outside of vanilla javascript - like Google Gears, Silverlight, and Flash.




回答2:


No way. not possible (with straight javascript). ever.

Think of the implication - I could visit a website which would be able to downloadd a bajillion Mb zip file to a location of their choice on my system AND then extract it.




回答3:


By design javascript can't access the filesystem.

It may be possible with ActiveX, java applets etc...




回答4:


If you are using Internet Explorer on Windows you can use ActiveX to exploit a bunch of COM objects that are available by default, such as using WScript.Shell to perform shell executes:

var shell = new ActiveXObject('WScript.Shell');
shell.run( '"unzip.exe command line stuff or whatever you want to do here..."' ); 

Obviously, this would require quite ridiculous security settings on the user's side and unless this is something you're putting together for your own use you should leave it up to the users to decide whether they want to download and extract your files or not.



来源:https://stackoverflow.com/questions/4508595/how-to-extract-the-zip-file-in-client-system-using-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!