-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
If the remaining chunk is smaller than the BUFFER_SIZE and it is the last chunk to read (very unlikely to happen, since large file already contains ~millions of lines), then the read bytes will interfere (duplicates with the buffer variable):
python_log_api/Server/lib/log_viewer.py
Line 125 in 3e30d97
| buffer = file.read(BUFFER_SIZE) + buffer |
Approach:
while position > 0 and len(result) < lines_to_read:
prev_position = position
position = max(0, position - BUFFER_SIZE)
file.seek(position)
if position == 0:
buffer = file.read(prev_position) + buffer
else:
buffer = file.read(BUFFER_SIZE) + buffer
cur_lines = buffer.split(b'\n')
if position != 0:
buffer = cur_lines.pop(0) # Keep the last partial line for the next read
for line in reversed(cur_lines):
if len(line) > 0:
result.appendleft(line.decode() + '\n')
if len(result) == lines_to_read:
breakMetadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working