小编Gab*_*jos的帖子

Javascript中的大blob文件

我有一个下载1GB文件的XHR对象.

function getFile(callback)
{
    var xhr = new XMLHttpRequest();
    xhr.onload = function () {
        if (xhr.status == 200) {
            callback.apply(xhr);
        }else{
            console.log("Request error: " + xhr.statusText);
        }
    };

    xhr.open('GET', 'download', true);
    xhr.onprogress = updateProgress;
    xhr.responseType = "arraybuffer";
    xhr.send();
}
Run Code Online (Sandbox Code Playgroud)

但File API无法将所有内容加载到内存中,即使是从内存中抛出的工作者......

btn.addEventListener('click', function() {
    getFile(function() {
        var worker = new Worker("js/saving.worker.js");
        worker.onmessage = function(e) {
            saveAs(e.data); // FileSaver.js it creates URL from blob... but its too large
        };

        worker.postMessage(this.response);
    });
});
Run Code Online (Sandbox Code Playgroud)

网络工作者

onmessage = function (e) {
    var view  = …
Run Code Online (Sandbox Code Playgroud)

javascript firefox large-files

10
推荐指数
2
解决办法
2802
查看次数

标签 统计

firefox ×1

javascript ×1

large-files ×1