html文件变成巨大,巨大的JavaScript HTML5 blob(从大ArrayBuffers)在客户端构建一个巨大的文件...

看起来你只是将数组数组连在一起?为什么不把数组缓冲区附加在一个巨大的blob中.您必须一次迭代并附加每个arrayBuffer.您将寻求文件撰写人的最后附加数组.并且只读你的巨大的blob的一部分,你会得到一个斑点的一块,以避免浏览器崩溃.

附加功能

function appendToFile(fPath,data,callback){

fs.root.getFile(fPath, {

create: false

}, function(fileEntry) {

fileEntry.createWriter(function(writer) {

writer.onwriteend = function(e) {

callback();

};

writer.seek(writer.length);

var blob = new Blob([data]);

writer.write(blob);

}, errorHandler);

}, errorHandler);

}

再次为了避免读取整个Blob,只有在生成您提到的文件时才读取您的巨型Blob的部分/块.

部分阅读功能

function getPartialBlobFromFile(fPath,start,stop,callback){

fs.root.getFile(fPath, {

creation:false

}, function(fileEntry){

fileEntry.file(function(file){

var reader = new FileReader();

reader.onloadend = function(evt){

if(evt.target.readyState == FileReader.DONE){

callback(evt.target.result);

}

};

stop = Math.min(stop,file.size);

reader.readAsArrayBuffer(file.slice(start,stop));

}, errorHandler)

}, errorHandler);

}

您可能必须保留索引,也许在您的巨型BLOB的标题部分 – 我需要知道更多,然后才能给出更准确的反馈.

更新 – 避免配额限制,临时与持久

以回应您的意见

由于您正在使用临时存储,您似乎遇到存储配额问题.以下是从google发现的here的一个片段

Temporary storage is shared among all web apps running in the browser. The shared pool can be up to half of the of available disk space. Storage already used by apps is included in the calculation of the shared pool; that is to say, the calculation is based on (available storage space + storage being used by apps) * .5 .

Each app can have up to 20% of the shared pool. As an example, if the total available disk space is 50 GB, the shared pool is 25 GB, and the app can have up to 5 GB. This is calculated from 20% (up to 5 GB) of half (up to 25 GB) of the available disk space (50 GB).

为了避免此限制,您必须切换到持久性,它将允许您配额到磁盘上的可用空间.为此,请使用以下内容来初始化文件系统而不是临时存储请求.

navigator.webkitPersistentStorage.requestQuota(1024*1024*5,

function(gB){

window.requestFileSystem(PERSISTENT, gB, onInitFs, errorHandler);

}, function(e){

console.log('Error', e);

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值