Bạn có thể sử dụng zip.js cho việc này. API này đã có API để tìm nạp nội dung được nén từ HTTP (xem zip.HttpReader hàm tạo) và để viết mã zip được tạo trên hệ thống tệp HTML5 (xem zip.FileWriter hàm tạo).
Dưới đây là một ví dụ sử dụng filesystem API: file
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
file:
// 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);
});
}
Nguồn
2013-01-06 12:48:58
bạn có thể có quyền truy cập vào tất cả các nội dung của 'resources' trong một trang (hình ảnh, tệp js \ css, v.v.) tôi không chắc chắn về lưu trữ thông qua JS – Sudarshan