如果您有一个 File
对象(例如,使用 FileSystem API 存储的对象),则可以向其中跳转并读取分块,而无需将整个文件读入内存:
var url = "filesystem:http://example.com/temporary/myfile.zip";
window.webkitResolveLocalFileSystemURL(url, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onload = function(e) {
var ab = e.target.result; // arrayBuffer containing bytes 0-10 of file.
var uInt8Arr = new Uint8Array(ab);
...
};
var blob = file.webkitSlice(0, 10, "application/zip"); // mimetype is optional
reader.readAsArrayBuffer(blob);
}, errorHandler);
}, errorHandler);