comparison mercurial/util.py @ 52927:fdae7c26d038

chunkbuffer: provide a "__iter__" pass through If the consumer just want to iterate over chunk of arbitrary size, the chunk buffer is just an overhead. So we provide a way to bypass it in such cases. It is put to use in the next changesets.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 27 Jan 2025 18:08:19 +0100
parents 483b0bb23085
children e4552f135e35
comparison
equal deleted inserted replaced
52926:d5ae681834e8 52927:fdae7c26d038
2795 2795
2796 self.iter = splitbig(in_iter) 2796 self.iter = splitbig(in_iter)
2797 self._queue = collections.deque() 2797 self._queue = collections.deque()
2798 self._chunkoffset = 0 2798 self._chunkoffset = 0
2799 2799
2800 def __iter__(self):
2801 while self._queue:
2802 chunk = self._queue.popleft()
2803 if self._chunkoffset:
2804 yield chunk[self._chunkoffset :]
2805 else:
2806 yield chunk
2807 self._chunkoffset = 0
2808 yield from self.iter
2809
2800 def read(self, l=None): 2810 def read(self, l=None):
2801 """Read L bytes of data from the iterator of chunks of data. 2811 """Read L bytes of data from the iterator of chunks of data.
2802 Returns less than L bytes if the iterator runs dry. 2812 Returns less than L bytes if the iterator runs dry.
2803 2813
2804 If size parameter is omitted, read everything""" 2814 If size parameter is omitted, read everything"""