Fix write_to/n mode a bit

This commit is contained in:
Oleksii Shevchuk 2018-03-09 10:15:22 +02:00
parent 1ea0bfa91a
commit d0c09887dc
1 changed files with 6 additions and 3 deletions

View File

@ -324,16 +324,19 @@ class Buffer(object):
if not forced_notify and not chunk_size:
for idx, chunk in enumerate(self._data):
bofft = 0
if self._bofft:
chunk = chunk[self._bofft:]
bofft = self._bofft
self._bofft = 0
lchunk = len(chunk)
if n is not None:
if total_read + lchunk > n:
self._bofft = lchunk - ( n - total_read )
chunk = chunk[:self._bofft]
chunk = chunk[:n - total_read]
self._bofft = bofft + n - total_read
total_read += len(chunk)
@ -383,7 +386,7 @@ class Buffer(object):
if notify and not forced_notify:
stream.flush()
return total_write
return total_read, total_write
def peek(self, n=-1, view=False):
"""