|
|
|
@ -14,16 +14,22 @@ class CappedBufferedReader(io.BufferedReader):
|
|
|
|
|
return super().read(size)
|
|
|
|
|
|
|
|
|
|
def seek(self, offset, whence=os.SEEK_SET):
|
|
|
|
|
if offset == 0 and whence == os.SEEK_END and self.capped_size is not None:
|
|
|
|
|
if self.capped_size < 0:
|
|
|
|
|
offset = 0
|
|
|
|
|
else:
|
|
|
|
|
real_end = super().seek(0, os.SEEK_END)
|
|
|
|
|
if self.capped_size > real_end:
|
|
|
|
|
offset = real_end
|
|
|
|
|
if self.capped_size is not NOne:
|
|
|
|
|
if offset == 0 and whence == os.SEEK_END:
|
|
|
|
|
if self.capped_size < 0:
|
|
|
|
|
offset = 0
|
|
|
|
|
else:
|
|
|
|
|
offset = self.capped_size
|
|
|
|
|
whence = os.SEEK_SET
|
|
|
|
|
real_end = super().seek(0, os.SEEK_END)
|
|
|
|
|
if self.capped_size > real_end:
|
|
|
|
|
offset = real_end
|
|
|
|
|
else:
|
|
|
|
|
offset = self.capped_size
|
|
|
|
|
self.capped_size -= offset
|
|
|
|
|
whence = os.SEEK_SET
|
|
|
|
|
elif whence == os.SEEK_SET:
|
|
|
|
|
current_pos = self.tell()
|
|
|
|
|
if current_pos > offset:
|
|
|
|
|
self.capped_size += current_pos - offset
|
|
|
|
|
return super().seek(offset, whence)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|