Onionr/src/utils/readoffset.py
2020-10-17 07:51:28 +00:00

18 lines
421 B
Python

"""Onionr - Private P2P Communication.
read from a file from an offset (efficiently)
"""
from collections import namedtuple
OffsetReadResult = namedtuple('OffsetReadResult', ['data', 'new_offset'])
def read_from_offset(file_path, offset=0):
with open(file_path, 'rb') as f:
if offset:
f.seek(offset)
data = f.read()
offset = f.tell()
return OffsetReadResult(data, offset)