Convenience factory function to create from a filename. :type start_byte: int :param start_byte: The first byte from which to start reading. :type chunk_size: int :param chunk_size: The max chunk size to read. Trying to read pass the end of the chunk si
(
cls,
filename,
start_byte,
chunk_size,
callbacks=None,
enable_callbacks=True,
)
| 468 | |
| 469 | @classmethod |
| 470 | def from_filename( |
| 471 | cls, |
| 472 | filename, |
| 473 | start_byte, |
| 474 | chunk_size, |
| 475 | callbacks=None, |
| 476 | enable_callbacks=True, |
| 477 | ): |
| 478 | """Convenience factory function to create from a filename. |
| 479 | |
| 480 | :type start_byte: int |
| 481 | :param start_byte: The first byte from which to start reading. |
| 482 | |
| 483 | :type chunk_size: int |
| 484 | :param chunk_size: The max chunk size to read. Trying to read |
| 485 | pass the end of the chunk size will behave like you've |
| 486 | reached the end of the file. |
| 487 | |
| 488 | :type full_file_size: int |
| 489 | :param full_file_size: The entire content length associated |
| 490 | with ``fileobj``. |
| 491 | |
| 492 | :type callbacks: function(amount_read) |
| 493 | :param callbacks: Called whenever data is read from this object. |
| 494 | |
| 495 | :type enable_callbacks: bool |
| 496 | :param enable_callbacks: Indicate whether to invoke callback |
| 497 | during read() calls. |
| 498 | |
| 499 | :rtype: ``ReadFileChunk`` |
| 500 | :return: A new instance of ``ReadFileChunk`` |
| 501 | |
| 502 | """ |
| 503 | f = open(filename, 'rb') |
| 504 | f.seek(start_byte) |
| 505 | file_size = os.fstat(f.fileno()).st_size |
| 506 | return cls(f, chunk_size, file_size, callbacks, enable_callbacks) |
| 507 | |
| 508 | def _calculate_file_size( |
| 509 | self, fileobj, requested_size, start_byte, actual_file_size |