save selection to file if above threshold

This commit is contained in:
2021-10-31 12:30:06 +01:00
parent 86de0b9830
commit 79f9219e9a
2 changed files with 27 additions and 6 deletions

View File

@@ -56,6 +56,18 @@ class LogFileModel:
bytes = f.read(end_byte - start_byte)
return bytes.decode("utf8", errors="ignore")
def write_range(self, start_byte: int, end_byte: int, file: str):
print("write range: %d - %d -> %s" % (start_byte, end_byte, file))
with self._lock, open(self._file, 'rb') as source, open(file, "w+b") as target:
offset = start_byte
source.seek(offset)
while offset < end_byte:
new_offset = min(offset + 1024 * 1024, end_byte)
buffer_size = new_offset - offset
buffer = source.read(buffer_size)
target.write(buffer)
offset = new_offset
def data(self, byte_offset, scroll_lines, lines) -> List[Line]:
# print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines))
lines_before_offset: List[Line] = []