Looks like this would read in the entire file into memory?  Here's the approach we took in ``skimage``:

https://github.com/scikit-image/scikit-image/blob/master/skimage/_build.py#L61

These two functions are quite well tested--feel free to adapt for use here.