Downloaded File

class b2sdk.v2.DownloadedFile(download_version, download_manager, range_, response, encryption, progress_listener, write_buffer_size=None, check_hash=True)[source]

Result of a successful download initialization. Holds information about file’s metadata and allows to perform the download.

Parameters:
save(file, allow_seeking=None)[source]

Read data from B2 cloud and write it to a file-like object

Parameters:
  • file (BinaryIO) – a file-like object

  • allow_seeking (Optional[bool]) – if False, download strategies that rely on seeking to write data (parallel strategies) will be discarded.

Return type:

None

save_to(path_, mode=None, allow_seeking=None)[source]

Open a local file and write data from B2 cloud to it, also update the mod_time.

Parameters:
  • path – path to file to be opened

  • mode (Optional[Literal['wb', 'wb+']]) – mode in which the file should be opened

  • allow_seeking (Optional[bool]) – if False, download strategies that rely on seeking to write data (parallel strategies) will be discarded.

  • path_ (str | Path) –

Return type:

None

class b2sdk.v2.MtimeUpdatedFile(path_, mod_time_millis, mode='wb+', buffering=None)[source]

Helper class that facilitates updating a files mod_time after closing.

Over the time this class has grown, and now it also adds better exception handling.

Usage:

Parameters:
property path_: str
write(value)[source]

This method is overwritten (monkey-patched) in __enter__ for performance reasons

read(*a)[source]

This method is overwritten (monkey-patched) in __enter__ for performance reasons

seekable()[source]

Return whether object supports random access.

If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().

Return type:

bool

seek(offset, whence=0)[source]

Change the stream position to the given byte offset.

offset

The stream position, relative to ‘whence’.

whence

The relative position to seek from.

The offset is interpreted relative to the position indicated by whence. Values for whence are:

  • os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive

  • os.SEEK_CUR or 1 – current stream position; offset may be negative

  • os.SEEK_END or 2 – end of stream; offset is usually negative

Return the new absolute position.

tell()[source]

Return current stream position.