b2sdk.stream.progress Streams with progress reporting

class b2sdk.stream.progress.AbstractStreamWithProgress(stream, progress_listener, offset=0)[source]

Bases: StreamWrapper

Wrap a file-like object and updates a ProgressListener as data is read / written. In the abstract class, read and write methods do not update the progress - child classes shall do it.

__init__(stream, progress_listener, offset=0)[source]
Parameters:
  • stream – the stream to read from or write to

  • progress_listener (b2sdk.v2.AbstractProgressListener) – the listener that we tell about progress

  • offset (int) – the starting byte offset in the file

class b2sdk.stream.progress.ReadingStreamWithProgress(*args, **kwargs)[source]

Bases: AbstractStreamWithProgress

Wrap a file-like object, updates progress while reading.

__init__(*args, **kwargs)[source]
Parameters:
  • stream – the stream to read from or write to

  • progress_listener (b2sdk.v2.AbstractProgressListener) – the listener that we tell about progress

  • offset (int) – the starting byte offset in the file

read(size=None)[source]

Read data from the stream.

Parameters:

size (int) – number of bytes to read

Returns:

data read from the stream

seek(pos, whence=0)[source]

Seek to a given position in the stream.

Parameters:

pos (int) – position in the stream

Returns:

new absolute position

Return type:

int

class b2sdk.stream.progress.WritingStreamWithProgress(stream, progress_listener, offset=0)[source]

Bases: AbstractStreamWithProgress

Wrap a file-like object; updates progress while writing.

write(data)[source]

Write data to the stream.

Parameters:

data (bytes) – data to write to the stream