在浏览器中随机访问文件 File API
我可以使用 File API 使用 reader.readAsArrayBuffer(file) 读取整个文件;
const inputElement = document.getElementById("input");
inputElement.addEventListener("change", handleFiles, false);
function handleFiles() {
const fileList = this.files;
if (fileList.length != 1) return
const file = fileList[0];
const reader = new FileReader();
reader.onload = function(e) {
console.log("e.target.result", e.target.result);
...
}
reader.readAsArrayBuffer(file);
如何在浏览器中对文件执行随机读取?例如 reader.readAsArrayBuffer(file, offset, length);
我需要的数据位于文件末尾,因此在部分读取后中止不是解决方案。
我只想读取多 GB 文件的一小部分 - 将其全部读取到 RAM 不是一个选择。我该怎么做?
I can use the File API to read the whole file with reader.readAsArrayBuffer(file);
const inputElement = document.getElementById("input");
inputElement.addEventListener("change", handleFiles, false);
function handleFiles() {
const fileList = this.files;
if (fileList.length != 1) return
const file = fileList[0];
const reader = new FileReader();
reader.onload = function(e) {
console.log("e.target.result", e.target.result);
...
}
reader.readAsArrayBuffer(file);
How do I perform a random read on a file in the browser? e.g. reader.readAsArrayBuffer(file, offset, length);
The data I need is at the end of the file, so aborting after a partial read is not a solution.
I only want to read a small part of a multi-GB file - reading it all to RAM is not an option. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论