b2sdk.stream.wrapper StreamWrapper

class b2sdk.stream.wrapper.StreamWrapper(stream)[source]

Bases: IOBase

Wrapper for a file-like object.

__init__(stream)[source]
Parameters:

stream – the stream to read from or write to

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().

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

tell()[source]

Return current stream position.

Return type:

int

truncate(size=None)[source]

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Return the new size.

flush()[source]

Flush the stream.

readable()[source]

Return whether object was opened for reading.

If False, read() will raise OSError.

read(size=None)[source]

Read data from the stream.

Parameters:

size (int) – number of bytes to read

Returns:

data read from the stream

writable()[source]

Return whether object was opened for writing.

If False, write() will raise OSError.

write(data)[source]

Write data to the stream.

Parameters:

data – a data to write to the stream

class b2sdk.stream.wrapper.StreamWithLengthWrapper(stream, length=None)[source]

Bases: StreamWrapper

Wrapper for a file-like object that supports __len__ interface

__init__(stream, length=None)[source]
Parameters:
  • stream – the stream to read from or write to

  • length (int) – length of the stream