b2sdk.transfer.outbound.upload_source

class b2sdk.transfer.outbound.upload_source.UploadMode(value)[source]

Bases: Enum

Mode of file uploads

FULL = 1

always upload the whole file

INCREMENTAL = 2

use incremental uploads when possible

class b2sdk.transfer.outbound.upload_source.AbstractUploadSource[source]

Bases: OutboundTransferSource

The source of data for uploading to b2.

abstract get_content_sha1() Optional[Sha1HexDigest][source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

abstract open() IOBase[source]

Returns a binary file-like object from which the data can be read.

is_upload() bool[source]

Returns True if outbound source is an upload source.

is_copy() bool[source]

Returns True if outbound source is a copy source.

is_sha1_known() bool[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

class b2sdk.transfer.outbound.upload_source.UploadSourceBytes(data_bytes: Union[bytes, bytearray], content_sha1: Optional[Sha1HexDigest] = None)[source]

Bases: AbstractUploadSource

__init__(data_bytes: Union[bytes, bytearray], content_sha1: Optional[Sha1HexDigest] = None)[source]

Initialize upload source using given bytes.

Parameters:
  • data_bytes – Data that is to be uploaded.

  • content_sha1 – SHA1 hexdigest of the data, or None.

get_content_length() int[source]

Returns the number of bytes of data in the file.

get_content_sha1() Optional[Sha1HexDigest][source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

open()[source]

Returns a binary file-like object from which the data can be read.

is_sha1_known() bool[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

class b2sdk.transfer.outbound.upload_source.UploadSourceLocalFileBase(local_path: Union[PathLike, str], content_sha1: Optional[Sha1HexDigest] = None)[source]

Bases: AbstractUploadSource

__init__(local_path: Union[PathLike, str], content_sha1: Optional[Sha1HexDigest] = None)[source]

Initialize upload source using provided path.

Parameters:
  • local_path – Any path-like object that points to a file to be uploaded.

  • content_sha1 – SHA1 hexdigest of the data, or None.

check_path_and_get_size() None[source]
get_content_length() int[source]

Returns the number of bytes of data in the file.

get_content_sha1() Optional[Sha1HexDigest][source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

open()[source]

Returns a binary file-like object from which the data can be read.

is_sha1_known() bool[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

class b2sdk.transfer.outbound.upload_source.UploadSourceLocalFileRange(local_path: Union[PathLike, str], content_sha1: Optional[Sha1HexDigest] = None, offset: int = 0, length: Optional[int] = None)[source]

Bases: UploadSourceLocalFileBase

__init__(local_path: Union[PathLike, str], content_sha1: Optional[Sha1HexDigest] = None, offset: int = 0, length: Optional[int] = None)[source]

Initialize upload source using provided path.

Parameters:
  • local_path – Any path-like object that points to a file to be uploaded.

  • content_sha1 – SHA1 hexdigest of the data, or None.

  • offset – Position in the file where upload should start from.

  • length – Amount of data to be uploaded. If None, length of the remainder of the file is taken.

open()[source]

Returns a binary file-like object from which the data can be read.

class b2sdk.transfer.outbound.upload_source.UploadSourceLocalFile(local_path: Union[PathLike, str], content_sha1: Optional[Sha1HexDigest] = None)[source]

Bases: UploadSourceLocalFileBase

get_incremental_sources(file_version: BaseFileVersion, min_part_size: Optional[int] = None) List[OutboundTransferSource][source]

Split the upload into a copy and upload source constructing an incremental upload

This will return a list of upload sources. If the upload cannot split, the method will return [self].

class b2sdk.transfer.outbound.upload_source.UploadSourceStream(stream_opener: Callable[[], IOBase], stream_length: Optional[int] = None, stream_sha1: Optional[Sha1HexDigest] = None)[source]

Bases: AbstractUploadSource

__init__(stream_opener: Callable[[], IOBase], stream_length: Optional[int] = None, stream_sha1: Optional[Sha1HexDigest] = None)[source]

Initialize upload source using arbitrary function.

Parameters:
  • stream_opener – A function that opens a stream for uploading.

  • stream_length – Length of the stream. If None, data will be calculated from the stream the first time it’s required.

  • stream_sha1 – SHA1 of the stream. If None, data will be calculated from the stream the first time it’s required.

get_content_length() int[source]

Returns the number of bytes of data in the file.

get_content_sha1() Optional[Sha1HexDigest][source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

open()[source]

Returns a binary file-like object from which the data can be read.

is_sha1_known() bool[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

class b2sdk.transfer.outbound.upload_source.UploadSourceStreamRange(stream_opener: Callable[[], IOBase], offset: int = 0, stream_length: Optional[int] = None, stream_sha1: Optional[Sha1HexDigest] = None)[source]

Bases: UploadSourceStream

__init__(stream_opener: Callable[[], IOBase], offset: int = 0, stream_length: Optional[int] = None, stream_sha1: Optional[Sha1HexDigest] = None)[source]

Initialize upload source using arbitrary function.

Parameters:
  • stream_opener – A function that opens a stream for uploading.

  • offset – Offset from which stream should be uploaded.

  • stream_length – Length of the stream. If None, data will be calculated from the stream the first time it’s required.

  • stream_sha1 – SHA1 of the stream. If None, data will be calculated from the stream the first time it’s required.

open()[source]

Returns a binary file-like object from which the data can be read.