DeferredRequestStream
ClassPrivateContextSource
stream = DeferredRequestStream(
info: CachedFileInfo,
data: CachedRequest
)
with stream as resp:
resp: ProtocolResponse
Deferred data stream forwarded from the response of a pre-configured request.
By entering the context of this class, a connection to the remote resource will be established. Within this context, a data stream can be read and forwarded.
Arguments
Argument | Type | Required | |
---|---|---|---|
info | CachedFileInfo | The information loaded from the cache. | |
data | CachedRequest | The request configuration loaded from the cache. |
Methods
close
stream.close()
Close all connections if they exist.
When exiting from the context, this method will be called automatically.
provide
data: Iterator[bytes] = stream.provide(chunk_size: int = 1024 * 1024)
Create the data provider of this deferred request stream.
Note that this method is designed for being used outside the context. When using this method, it will maintain the context within this stream provider. In other words, the context will be exited when this method get finalized.
The returned iterator data
will let the context of stream
active. If the iterator
is to be dropped, it is recommended that the close()
method should be called
explictly.
Requires
Argument | Type | Required | |
---|---|---|---|
chunk_size | int | The chunk size used for forwarding the data. |
Returns
Argument | Type | |
---|---|---|
data | Iterator[bytes] | A stream created by this method. |