See https://github.com/Toblerity/Fiona/issues/409 and https://github.com/mapbox/rasterio/issues/839.
I guess I'm sorta coming around to the idea that rasterio.open() could accept a file-like object and hide the MemoryFile details from users, removing some boilerplate from their programs. I've written a couple of new tests to help this discussion.
https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R123 is what a user must do now:
with MemoryFile(file_object.read()) as memfile:
with memfile.open() as src:
# Use the dataset object `src`.
Future usage might be like https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R135
with rasterio.open(file_object) as src:
# Use the dataset object `src`.
We can't pass a Python file object to GDAL, so the byes of the file object must be read and then used to initialize a MemoryFile within rasterio.open(). How that MemoryFile would be managed isn't clear to me at the moment.
Most helpful comment
https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R123 is what a user must do now:
Future usage might be like https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R135
We can't pass a Python file object to GDAL, so the byes of the file object must be read and then used to initialize a
MemoryFilewithinrasterio.open(). How thatMemoryFilewould be managed isn't clear to me at the moment.