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.
To unzip files with JavaScript, we use the JSZip library. to create the zip JSZip object. Then we call zip. load to load the file that we get from the file input.
Do one of the following: To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location. To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With