Seek into local files with the File System API

Published on Updated on

If you have a File object (say, one stored using the FileSystem API), it's possible to seek into it and read chunks without reading the entire file into memory:

var url = "filesystem:http://example.com/temporary/myfile.zip";

window.webkitResolveLocalFileSystemURL(url, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();

reader.onload = function(e) {
var ab = e.target.result; // arrayBuffer containing bytes 0-10 of file.
var uInt8Arr = new Uint8Array(ab);
...
};

var blob = file.webkitSlice(0, 10, "application/zip"); // mimetype is optional
reader.readAsArrayBuffer(blob);
}, errorHandler);
}, errorHandler);

Updated on Improve article

Back

Debugging the Filesystem API

Next

HTML5 Libraries/polyfills - Mid July

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.