b2sdk._internal.transfer.inbound.downloader.abstract – Downloader base class

class b2sdk._internal.transfer.inbound.downloader.abstract.EmptyHasher(*args, **kwargs)[source]

Bases: object

__init__(*args, **kwargs)[source]
update(data)[source]
digest()[source]
hexdigest()[source]
copy()[source]
class b2sdk._internal.transfer.inbound.downloader.abstract.AbstractDownloader(thread_pool=None, force_chunk_size=None, min_chunk_size=None, max_chunk_size=None, align_factor=None, check_hash=True, **kwargs)[source]

Bases: object

Abstract class for downloaders.

Variables:
  • REQUIRES_SEEKING – if True, the downloader requires the ability to seek in the file object.

  • SUPPORTS_DECODE_CONTENT – if True, the downloader supports decoded HTTP streams. In practice, this means that the downloader can handle HTTP responses which already have the content decoded per Content-Encoding and, more likely than not, of a different length than requested.

Parameters:
REQUIRES_SEEKING = True
SUPPORTS_DECODE_CONTENT = True
DEFAULT_THREAD_POOL_CLASS

alias of ThreadPoolExecutor

DEFAULT_ALIGN_FACTOR = 4096
__init__(thread_pool=None, force_chunk_size=None, min_chunk_size=None, max_chunk_size=None, align_factor=None, check_hash=True, **kwargs)[source]
Parameters:
is_suitable(download_version, allow_seeking)[source]

Analyze download_version (possibly against options passed earlier to constructor to find out whether the given download request should be handled by this downloader).

Parameters:
abstract download(file, response, download_version, session, encryption=None)[source]

Download target to a file-like object.

Parameters:
  • file (IOBase) – file-like object to write to

  • response (Response) – requests.Response of b2_download_url_by_* endpoint with the target object

  • download_version (DownloadVersion) – DownloadVersion of an object being downloaded

  • session (B2Session) – B2Session to be used for downloading

  • encryption (Optional[EncryptionSetting]) – optional Encryption setting

Return type:

tuple[int, str]

Returns:

(bytes_read, actual_sha1) please note bytes_read may be different from bytes written to a file object if decode_content=True