下载多个文件和 zip - Chrome 扩展 [英] Downloading multiple files and zip - Chrome extension

查看:38
本文介绍了下载多个文件和 zip - Chrome 扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将多个图像下载到沙盒文件系统中(没有另存为"对话框,或者最多只有一个另存为对话框)?

Is it possible to download multiple images into the sandbox file system (without the "save as" dialog box, or at-max one saveas dialog) ?

下载后,我想将它们压缩成一个..是否有任何 javascript 存档库?

after downloading them, i'd like to ZIP them into one.. is there any javascript archive library?

提前致谢..

推荐答案

你可以使用 zip.js 为此.它已经有用于从 HTTP 中获取要压缩的内容的 API(参见 zip.HttpReader 构造函数)并用于在 HTML5 文件系统上编写生成的 zip(参见 zip.FileWriter 构造函数).

You can use zip.js for this. It does already have API for fetching contents to be zipped from HTTP (cf. zip.HttpReader constructor) and for writing generated zip on HTML5 filesystem (cf. zip.FileWriter constructor).

以下是使用 文件系统 API 的示例:

Here is an example using the filesystem API:

index.html 文件:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Zip JSON data from the BBC into HTML5 FileSystem</title>
</head>
<body>
  <script src="zip.js"></script>
  <script src="zip-fs.js"></script>
  <script src="zip-ext.js"></script>
  <script src="example.js"></script>
</body>
</html>

example.js 文件:

// create a zip virtual filesystem
var fs = new zip.fs.FS();

// add some files into the zip filesystem 

// add the "bbc-music.json" file in the root directory
fs.root.addHttpContent("bbc-music.json", 
  "http://www.bbc.co.uk/programmes/genres/music.json");
// add the "bbc-learning.json" file in the root directory
fs.root.addHttpContent("bbc-learning.json", 
  "http://www.bbc.co.uk/programmes/genres/learning.json");

// create a file named "test.zip" in the root directory of the HTML5 filesystem 
createFile("test.zip", function(fileEntry) {
  // export the zip content into "test.zip" file
  fs.root.exportFileEntry(fileEntry, function() {
    console.log("done");
  });
});

// function to create a file in the HTML5 temporary filesystem
function createFile(filename, callback) {
  webkitRequestFileSystem(TEMPORARY, 4 * 1024 * 1024, function(fs) {
    fs.root.getFile(filename, { create : true }, callback);
  });
}

这篇关于下载多个文件和 zip - Chrome 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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