StorageStreamDownloader Class
A streaming object to download from Azure Storage.
- Inheritance
-
builtins.objectStorageStreamDownloader
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
- config
- start_range
- end_range
- validate_content
- encryption_options
- max_concurrency
- name
- container
- encoding
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
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
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
Return type
download_to_stream
Download the contents of this blob to a stream.
download_to_stream(stream, max_concurrency=1)
Parameters
- stream
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
Returns
The properties of the downloaded blob.
Return type
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
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
Feedback
Submit and view feedback for