b2sdk.stream.chained ChainedStream

class b2sdk.stream.chained.ChainedStream(stream_openers)[source]

Bases: b2sdk.stream.base.ReadOnlyStreamMixin, io.IOBase

Chains multiple streams in single stream, sort of what itertools.chain does for iterators.

Cleans up buffers of underlying streams when closed.

Can be seeked to beginning (when retrying upload, for example). Closes underlying streams as soon as they reaches EOF, but clears their buffers when the chained stream is closed for underlying streams that follow b2sdk.v1.StreamOpener cleanup interface, for example b2sdk.v1.CachedBytesStreamOpener

__init__(stream_openers)[source]
Parameters

stream_openeres (list) – list of callables that return opened streams

property stream

Return currently processed stream.

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

tell()[source]

Return current stream position.

seek(pos, whence=0)[source]

Resets stream to the beginning.

Parameters
  • pos (int) – only allowed value is 0

  • whence (int) – only allowed value is 0

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,None) – number of bytes to read. If omitted, None, or negative data is read and returned until EOF is reached

Returns

data read from the stream

close()[source]

Flush and close the IO object.

This method has no effect if the file is already closed.

class b2sdk.stream.chained.StreamOpener[source]

Bases: object

Abstract class to define stream opener with cleanup.

cleanup()[source]

Clean up stream opener after chained stream closes.

Can be used for cleaning cached data that are stored in memory to allow resetting chained stream without getting this data more than once, eg. data downloaded from external source.