Partially load data from files via File API in Javascript

156 Views Asked by At

With File API it is possible load data from local files into the browser memory via Javascript. I'm accessing huge files (200MB and bigger) on a system that is low in available RAM (webapp on an mobile device). How can I use the W3C File API (or Cordovas File Api as a fallback) to partially load data (e.g. by specifying a byte range) from files?

1

There are 1 best solutions below

0
On

The solution is to use File.slice(). Notice that File inherits from Blob and thereby receives its slice() method.

var blob = file.slice(startingByte, endindByte);
reader.readAsBinaryString(blob);

Source of this information is HTML5Rocks.com. A full example can be found there.