Random access to a file in browser File API

319 Views Asked by At

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?

0

There are 0 best solutions below