Given a file object shown below:: |___________________________________________________| 0 | | full_file_size |----chunk_size---| f.tell() :type fileobj: file :param
(
self,
fileobj,
chunk_size,
full_file_size,
callbacks=None,
enable_callbacks=True,
close_callbacks=None,
)
| 406 | |
| 407 | class ReadFileChunk: |
| 408 | def __init__( |
| 409 | self, |
| 410 | fileobj, |
| 411 | chunk_size, |
| 412 | full_file_size, |
| 413 | callbacks=None, |
| 414 | enable_callbacks=True, |
| 415 | close_callbacks=None, |
| 416 | ): |
| 417 | """ |
| 418 | |
| 419 | Given a file object shown below:: |
| 420 | |
| 421 | |___________________________________________________| |
| 422 | 0 | | full_file_size |
| 423 | |----chunk_size---| |
| 424 | f.tell() |
| 425 | |
| 426 | :type fileobj: file |
| 427 | :param fileobj: File like object |
| 428 | |
| 429 | :type chunk_size: int |
| 430 | :param chunk_size: The max chunk size to read. Trying to read |
| 431 | pass the end of the chunk size will behave like you've |
| 432 | reached the end of the file. |
| 433 | |
| 434 | :type full_file_size: int |
| 435 | :param full_file_size: The entire content length associated |
| 436 | with ``fileobj``. |
| 437 | |
| 438 | :type callbacks: A list of function(amount_read) |
| 439 | :param callbacks: Called whenever data is read from this object in the |
| 440 | order provided. |
| 441 | |
| 442 | :type enable_callbacks: boolean |
| 443 | :param enable_callbacks: True if to run callbacks. Otherwise, do not |
| 444 | run callbacks |
| 445 | |
| 446 | :type close_callbacks: A list of function() |
| 447 | :param close_callbacks: Called when close is called. The function |
| 448 | should take no arguments. |
| 449 | """ |
| 450 | self._fileobj = fileobj |
| 451 | self._start_byte = self._fileobj.tell() |
| 452 | self._size = self._calculate_file_size( |
| 453 | self._fileobj, |
| 454 | requested_size=chunk_size, |
| 455 | start_byte=self._start_byte, |
| 456 | actual_file_size=full_file_size, |
| 457 | ) |
| 458 | # _amount_read represents the position in the chunk and may exceed |
| 459 | # the chunk size, but won't allow reads out of bounds. |
| 460 | self._amount_read = 0 |
| 461 | self._callbacks = callbacks |
| 462 | if callbacks is None: |
| 463 | self._callbacks = [] |
| 464 | self._callbacks_enabled = enable_callbacks |
| 465 | self._close_callbacks = close_callbacks |
nothing calls this directly
no test coverage detected