B2 Utility functions

b2sdk.v2.b2_url_encode(s)[source]

URL-encode a unicode string to be sent to B2 in an HTTP header.

Parameters:

s (str) – a unicode string to encode

Returns:

URL-encoded string

Return type:

str

b2sdk.v2.b2_url_decode(s)[source]

Decode a Unicode string returned from B2 in an HTTP header.

Parameters:

s (str) – a unicode string to decode

Returns:

a Python unicode string.

Return type:

str

b2sdk.v2.choose_part_ranges(content_length, minimum_part_size)[source]

Return a list of (offset, length) for the parts of a large file.

Parameters:
  • content_length (int) – content length value

  • minimum_part_size (int) – a minimum file part size

Return type:

list

b2sdk.v2.fix_windows_path_limit(path)[source]

Prefix paths when running on Windows to overcome 260 character path length limit. See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath

Parameters:

path (str) – a path to prefix

Returns:

a prefixed path

Return type:

str

b2sdk.v2.format_and_scale_fraction(numerator, denominator, unit)[source]

Pick a good scale for representing a fraction, and format it.

Parameters:
  • numerator (int) – a numerator of a fraction

  • denominator (int) – a denominator of a fraction

  • unit (str) – an arbitrary unit name

Returns:

scaled and formatted fraction

Return type:

str

b2sdk.v2.format_and_scale_number(x, unit)[source]

Pick a good scale for representing a number and format it.

Parameters:
  • x (int) – a number

  • unit (str) – an arbitrary unit name

Returns:

scaled and formatted number

Return type:

str

b2sdk.v2.hex_sha1_of_stream(input_stream, content_length)[source]

Return the 40-character hex SHA1 checksum of the first content_length bytes in the input stream.

Parameters:
  • input_stream (Any) – stream object, which exposes read(int|None) method

  • content_length (int) – expected length of the stream

Return type:

str

b2sdk.v2.hex_sha1_of_bytes(data)[source]

Return the 40-character hex SHA1 checksum of the data.

Parameters:

data (bytes) –

Return type:

NewType(Sha1HexDigest, str)

class b2sdk.v2.TempDir[source]

Context manager that creates and destroys a temporary directory.

__enter__()[source]

Return the unicode path to the temp dir.

__exit__(exc_type, exc_val, exc_tb)[source]