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:
parent
a12ff42a80
commit
d880fce89e
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in New Issue