Fixed bug #18972

An alternate implementation of doda's patch at https://github.com/django/django/pull/415, that avoids the "offset" math in favor of just stuffing the data into a BytesIO and then .read()ing from it with a sentinel-style iterator.

Includes a unit test from a previous pull request, all tests pass.