Optimize file loading.

* Reduced number of canonical file queries
* Reduced number of byte array allocations
* Added buffering to streams