如何使用javascript在客户端系统中提取Zip文件 [英] how to extract the Zip file in client system using javascript

查看:117
本文介绍了如何使用javascript在客户端系统中提取Zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在server.i中有一个Zip文件正在下载zip文件保存到客户端system.now我想用javascript提取文件。
任何人请帮助我。
提前感谢。

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.

推荐答案

您可以使用Javascript在浏览器中解压缩内存中的zipfiles。

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

此答案显示如何。

浏览器中的js代码如下所示:

The js code in the browser looks like this:

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

var zipFile = new ZipFile(url, doneReading); 

DoSomethingWithEntries 方法内,提供,你可以摆弄代表提取的zip文件的对象。

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如上所示,您可以使用其名称,大小,日期等发出条目列表。

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

您还可以在每个zip条目上调用 extract()方法。 (此处未显示)
如果提取,则提取异步发生。内容被扩展为在浏览器javascript环境的内存中维护的字节数组或字符串(取决于条目是二进制还是文本)。然后,您可以从压缩条目或任何您喜欢的内容中显示提取的内容。

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.

我不相信你可以与文件系统进行交互,无论是阅读还是写作,除非你诉诸于vanilla javascript以外的东西 - 比如Google Gears,Silverlight和Flash 。

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.

这篇关于如何使用javascript在客户端系统中提取Zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆