Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

unzip a local zip archive with only one file, filename and contents will vary. JavaScript

  • SOLVED

I want to use jszip https://stuk.github.io/jszip/documentation/examples/read-local-file-api.html
to unzip a local zip archive with only one file (e.g. "mackenzie.zip ==> mackenzie.txt")

But the zip file name will vary and so will the file inside it. The zip file size <= 150K. I don't want to use node. Just plain js or jquery.


Maybe fileReader API will be helpful. Speed is not important. I want to save the content of the file to user-selectable location.

Answers (2)

2020-06-15

Monit jadhav answers:

I want to use jszip https://stuk.github.io/jszip/documentation/examples/read-local-file-api.html
to unzip a local zip archive with only one file (e.g. "mackenzie.zip ==> mackenzie.txt")

the code on the url is doing that it can take zip with any filename.

You can check for file size like below, this code replaces the last few lines of the demo code


if(files[i].size< 150000){
handleFile(files[i]);
}else{
alert("File is too Big")
}


I want to save the content of the file to user-selectable location.

Do you mean on the server or his local machine?

I dont think you can upload files without any kind of server side interaction. If not node then you need at least PHP to handle the server side upload


User180435 comments:

I want to save on the local machine.

2020-06-15

Arnav Joy answers:

Hi,
The link which showed has the code, and it work with any file name.
so what you looking for? can you please explain?
are you looking to implement that api to your site?
-Arnav


User180435 comments:

That code just reads and generates a summary of the zip file. But I need the contents of the file in a variable.


User180435 comments:

Yes, I am looking to implement that jszip api on my site.