raj*_*raj 6 javascript download archive google-chrome-extension
是否可以将多个图像下载到沙箱文件系统中(没有"另存为"对话框,或者最多只能保存一个对话框)?
下载后,我想把它们压缩成一个..有没有任何javascript存档库?
提前致谢..
您可以使用zip.js这一点.它已经有了用于获取要从HTTP压缩的内容的API(参见zip.HttpReader构造函数)以及用于在HTML5文件系统上编写生成的zip(参见zip.FileWriter构造函数).
以下是使用文件系统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>
Run Code Online (Sandbox Code Playgroud)
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);
});
}
Run Code Online (Sandbox Code Playgroud)
您可以将图像作为某些网页的常规部分访问,也可以通过XMLHTTPRequest
s 单独下载它们。之后,您可以使用JSZip JavaScript 库将它们压缩到一个存档中。zip 可以存储为文件,无需“另存为”对话框(尝试网站上的示例)。虽然我不确定你为什么需要沙箱。
还存在其他用于压缩的 JavaScript 库,例如,其他 SO 答案中提到了一些库。
归档时间: |
|
查看次数: |
5585 次 |
最近记录: |