StorageStreamDownloader Class

A streaming object to download from Azure Storage.

Inheritance
builtins.object
StorageStreamDownloader

Constructor

StorageStreamDownloader(clients=None, config=None, start_range=None, end_range=None, validate_content=None, encryption_options=None, max_concurrency=1, name=None, container=None, encoding=None, **kwargs)

Parameters

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

Variables

name
str

The name of the blob being downloaded.

container
str

The name of the container where the blob is.

properties
BlobProperties

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

size
int

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

Methods

chunks

Iterate over chunks in the download stream.

content_as_bytes

Download the contents of this file.

This operation is blocking until all data is downloaded.

content_as_text

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

This operation is blocking until all data is downloaded.

download_to_stream

Download the contents of this blob to a stream.

readall

Download the contents of this blob.

This operation is blocking until all data is downloaded. :rtype: bytes or str

readinto

Download the contents of this file to a stream.

chunks

Iterate over chunks in the download stream.

chunks() -> Iterator[bytes]

Return type

<xref:Iterator>[bytes]

Examples

Download a blob using chunks().


   # This returns a StorageStreamDownloader.
   stream = source_blob_client.download_blob()
   block_list = []

   # Read data in chunks to avoid loading all into memory at once
   for chunk in stream.chunks():
       # process your data (anything can be done here really. `chunk` is a byte array).
       block_id = str(uuid.uuid4())
       destination_blob_client.stage_block(block_id=block_id, data=chunk)
       block_list.append(BlobBlock(block_id=block_id))


content_as_bytes

Download the contents of this file.

This operation is blocking until all data is downloaded.

content_as_bytes(max_concurrency=1)

Parameters

max_concurrency
int
default value: 1

The number of parallel connections with which to download.

Return type

content_as_text

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

This operation is blocking until all data is downloaded.

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

Parameters

max_concurrency
int
default value: 1

The number of parallel connections with which to download.

encoding
str
default value: UTF-8

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

Return type

str

download_to_stream

Download the contents of this blob to a stream.

download_to_stream(stream, max_concurrency=1)

Parameters

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.

max_concurrency
default value: 1

Returns

The properties of the downloaded blob.

Return type

<xref:Any>

readall

Download the contents of this blob.

This operation is blocking until all data is downloaded. :rtype: bytes or str

readall() -> Union[bytes, str]

readinto

Download the contents of this file to a stream.

readinto(stream)

Parameters

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

The number of bytes read.

Return type

int