我不想将文件的整个内容读入内存;只是它的一部分,只在需要时。
然而,似乎我只能读取一个块(使用file.slice()
),而所有后续读取都返回零长度。有任何想法吗?
以下是第二次调用失败的代码的简化示例:
var chunkNo=0;
function readNextChunk()
{
var file=document.getElementsByTagName("input").item(0).files[0];
var blob=file.slice(100*chunkNo, 100);
var reader=new FileReader();
reader.onload=function(e) { console.log("No"+chunkNo+":\n"+reader.result);
chunkNo++;
};
reader.readAsText(blob);
}