def __init__(self, file_object, start, size):
"""
Build an object that will act like a BufferedReader object,
but constrained to a predetermined part of the file_object.
:param file_object: A file opened for reading in binary mode.
:param start: Start of the part within the file_object
:param size: Ideal size of the part. This will be set
to the number of bytes remaining in the
file if there aren't enough bytes remaining.
"""
self.file = file_object
self.bytes_read = 0
self.start = start
# Seek to the end of the file to see how many bytes remain
# from the start of the part.
self.file.seek(0, io.SEEK_END)
self.size = min(self.file.tell() - self.start, size)
# Reset the pointer to the start of the part.
self.file.seek(start, io.SEEK_SET)
评论列表
文章目录