我不想将文件的全部内容读入内存;仅部分内容,且仅按需提供。
然而,似乎我只能读取一次块(使用 a 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);
}