When iterating over a range of a file, always close it

This is needed on Pythons without reference counting garbage collectors (e.g.
PyPy).

Change-Id: I1d06eb8fe08ee6eeb45caa47b653d6af0bb18267