From 5fda0c9a77b76562ef8087ae6d5c5392e4e22f9e Mon Sep 17 00:00:00 2001 From: Greg Lange Date: Wed, 1 May 2013 21:16:18 +0000 Subject: [PATCH] Adds chunk_size to CompressingFileReader. Before when iterating using this object, the call to the underlying file object was made without a chunk_size. This is bad because this would cause the entire contents of the file to be read. Change-Id: I9956e5d2d693a6260252fff331d4f78f70179a6c --- swift/common/internal_client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py index 0b9c485d34..10549d112f 100644 --- a/swift/common/internal_client.py +++ b/swift/common/internal_client.py @@ -49,9 +49,11 @@ class CompressingFileReader(object): :param file_obj: File object to wrap. :param compresslevel: Compression level, defaults to 9. + :param chunk_size: Size of chunks read when iterating using object, + defaults to 4096. """ - def __init__(self, file_obj, compresslevel=9): + def __init__(self, file_obj, compresslevel=9, chunk_size=4096): self._f = file_obj self._compressor = compressobj( compresslevel, zlib.DEFLATED, -zlib.MAX_WBITS, zlib.DEF_MEM_LEVEL, @@ -60,6 +62,7 @@ class CompressingFileReader(object): self.first = True self.crc32 = 0 self.total_size = 0 + self.chunk_size = chunk_size def read(self, *a, **kw): """ @@ -96,7 +99,7 @@ class CompressingFileReader(object): return self def next(self): - chunk = self.read() + chunk = self.read(self.chunk_size) if chunk: return chunk raise StopIteration