StorageStreamDownloader Class

A streaming object to download from Azure Storage.

Inheritance
StorageStreamDownloader

Constructor

StorageStreamDownloader(clients: AzureBlobStorage = None, config: StorageConfiguration = None, start_range: int | None = None, end_range: int | None = None, validate_content: bool = None, encryption_options: Dict[str, Any] = None, max_concurrency: int = 1, name: str = None, container: str = None, encoding: str | None = None, download_cls: Callable | None = None, **kwargs: Any)

Parameters

Name Description
clients
Default value: None
config
Default value: None
start_range
Default value: None
end_range
Default value: None
validate_content
Default value: None
encryption_options
Default value: None
max_concurrency
Default value: 1
name
Default value: None
container
Default value: None
encoding
Default value: None
download_cls
Default value: None

Methods

chunks

Iterate over chunks in the download stream. Note, the iterator returned will iterate over the entire download content, regardless of any data that was previously read.

NOTE: If the stream has been partially read, some data may be re-downloaded by the iterator.

content_as_bytes

DEPRECATED: Download the contents of this file.

This operation is blocking until all data is downloaded.

This method is deprecated, use func:readall instead.

content_as_text

DEPRECATED: Download the contents of this blob, and decode as text.

This operation is blocking until all data is downloaded.

This method is deprecated, use func:readall instead.

download_to_stream

DEPRECATED: Download the contents of this blob to a stream.

This method is deprecated, use func:readinto instead.

read

Read the specified bytes or chars from the stream. If encoding was specified on download_blob, it is recommended to use the chars parameter to read a specific number of chars to avoid decoding errors. If size/chars is unspecified or negative all bytes will be read.

readall

Read the entire contents of this blob. This operation is blocking until all data is downloaded.

readinto

Download the contents of this file to a stream.

chunks

Iterate over chunks in the download stream. Note, the iterator returned will iterate over the entire download content, regardless of any data that was previously read.

NOTE: If the stream has been partially read, some data may be re-downloaded by the iterator.

chunks() -> Iterator[bytes]

Returns

Type Description

An iterator of the chunks in the download stream.

content_as_bytes

DEPRECATED: Download the contents of this file.

This operation is blocking until all data is downloaded.

This method is deprecated, use func:readall instead.

content_as_bytes(max_concurrency=1)

Parameters

Name Description
max_concurrency
int

The number of parallel connections with which to download.

Default value: 1

Returns

Type Description

The contents of the file as bytes.

content_as_text

DEPRECATED: Download the contents of this blob, and decode as text.

This operation is blocking until all data is downloaded.

This method is deprecated, use func:readall instead.

content_as_text(max_concurrency=1, encoding='UTF-8')

Parameters

Name Description
max_concurrency
int

The number of parallel connections with which to download.

Default value: 1
encoding
str

Test encoding to decode the downloaded bytes. Default is UTF-8.

Default value: UTF-8

Returns

Type Description
str

The content of the file as a str.

download_to_stream

DEPRECATED: Download the contents of this blob to a stream.

This method is deprecated, use func:readinto instead.

download_to_stream(stream, max_concurrency=1)

Parameters

Name Description
stream
Required
IO[<xref:T>]

The stream to download to. This can be an open file-handle, or any writable stream. The stream must be seekable if the download uses more than one parallel connection.

max_concurrency
int

The number of parallel connections with which to download.

Default value: 1

Returns

Type Description
Any

The properties of the downloaded blob.

read

Read the specified bytes or chars from the stream. If encoding was specified on download_blob, it is recommended to use the chars parameter to read a specific number of chars to avoid decoding errors. If size/chars is unspecified or negative all bytes will be read.

read(size: int = -1) -> T

Parameters

Name Description
size
int

The number of bytes to download from the stream. Leave unspecified or set negative to download all bytes.

Default value: -1

Keyword-Only Parameters

Name Description
chars

The number of chars to download from the stream. Leave unspecified or set negative to download all chars. Note, this can only be used when encoding is specified on download_blob.

Returns

Type Description
<xref:T>

The requested data as bytes or a string if encoding was specified. If the return value is empty, there is no more data to read.

readall

Read the entire contents of this blob. This operation is blocking until all data is downloaded.

readall() -> T

Returns

Type Description
<xref:T>

The requested data as bytes or a string if encoding was specified.

readinto

Download the contents of this file to a stream.

readinto(stream: IO[bytes]) -> int

Parameters

Name Description
stream
Required

The stream to download to. This can be an open file-handle, or any writable stream. The stream must be seekable if the download uses more than one parallel connection.

Returns

Type Description
int

The number of bytes read.

Attributes

container

The name of the container where the blob is.

container: str

name

The name of the blob being downloaded.

name: str

properties

The properties of the blob being downloaded. If only a range of the data is being downloaded, this will be reflected in the properties.

properties: BlobProperties

size

The size of the total data in the stream. This will be the byte range if specified, otherwise the total size of the blob.

size: int