JSZip unzipping error

夙愿已清 提交于 2020-04-14 06:25:07

问题


Trying to handle with JSZip library.

I am having an issue to unzip a file. Here's a plunker demo. As you can see I can successfully zip a content, but when I try to unzip a zipped content I get an error (can be seen in console):

Uncaught Error: Corrupted zip : can't find end of central directory 

Any ideas why this happens?

In any case, here's what I am trying to achieve: I have an textarea on my page. Upon click I want to zip textarea content and send zipped data to server. Another call must be able to receive a zipped data, unzip it and replace textarea text with unzipped one. Everything works ok, except unzipping problem.


回答1:


The generateAsync() method defaults to a base64 output but the loadAsync() method only see a string. You have two solutions :

  • change the generated format with `generateAsync({type:"uint8array"}) (see here)
  • or tell the load method that you are loading base64 content : loadAsync(data,{base64:true}) (see here)



回答2:


As answered by David has resolved my problem on my local workstation running Windows 10 OS. However it is failed on the Server running RHEL OS.

I have to fix it by switching to yauzl package for unzipping. It is recommended as mention on package's official repository, with specified merge pull 383.



来源:https://stackoverflow.com/questions/24610206/jszip-unzipping-error

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