Thursday, June 2, 2016

FileReader compatibility use and performance

The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer.

There are different approaches of reading files in order to upload them.

I came across a problem when trying to read large files. In my case these files where APK and IPA files (Android and IOS mobile applications)

I found a specific problem that actually reading very large files (over 160MB), was not possible to Firefox.

I found that the problem was generated with the following code line:

var fr = new FileReader();
fr.readAsDataURL(application);


readAsDataURL cannot finish its job and no error is provided, as well, the onload/onloadend 
function is not applied.

The solution was replacing the readAsDataURL by the readAsArrayBuffer.

I also found that the reading is performed much faster with the readAsArrayBuffer. Specially for
large files.
Both methods are compatible with all new browsers http://caniuse.com/#feat=filereader

Files: 
Small file: ipa, len: 5.5M
Large file: ipa, len: 158M


Browser          readAsDataURL       readAsArrayBuffer
                  Small File              Large File                          Small File               Large File
Edge 1021 12332 116 3034
IE 10 114 3051 16 256
Chrome 18 995 33 982
Firefox 345 5890 13 119


No comments:

Post a Comment