Fix BlobIterator

Now we do not update index during iteration which leads
to the fact that BlobIterator returns incorrect data if
a file size exceeds chunk size (default 65536 bytes)

Change-Id: Id2b5f9efe29518106e097d237827ec481f22127b
This commit is contained in:
Mike Fedosin 2018-01-10 19:06:58 +01:00
parent a12ff42a80
commit d880fce89e
2 changed files with 10 additions and 0 deletions

View File

@ -518,6 +518,7 @@ class BlobIterator(object):
while bytes_left > 0:
data = self.data[i * self.chunk_size:(i + 1) * self.chunk_size]
bytes_left -= len(data)
i += 1
yield data
raise StopIteration()

View File

@ -238,6 +238,15 @@ class TestReaders(base.BaseTestCase):
self.assertEqual(BYTES, bytes_read)
def test_blob_iterator_big_data(self):
BYTES = 1000000
bytes_read = 0
stream = [b'*'] * BYTES
for chunk in utils.BlobIterator(stream):
bytes_read += len(chunk)
self.assertEqual(BYTES, bytes_read)
class TestKeyCert(base.BaseTestCase):