Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cachecontrol/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ def _close(self):
# and allows the garbage collector to do it's thing normally.
self.__callback = None

# Closing the BytesIO stream releases memory. Important when caching
# big files.
self.__buf.close()

def read(self, amt=None):
data = self.__fp.read(amt)
self.__buf.write(data)
if data:
# We may be dealing with b'', a sign that things are over:
# it's passed e.g. after we've already closed self.__buf.
self.__buf.write(data)
if self.__is_fp_closed():
self._close()

Expand Down