Skip to content

[Storage] Finalized managed_download and managed_download_to drop-in replacements#4068

Merged
vincenttran-msft merged 11 commits intoAzure:mainfrom
vincenttran-msft:vincenttran/promote_download
Apr 4, 2026
Merged

[Storage] Finalized managed_download and managed_download_to drop-in replacements#4068
vincenttran-msft merged 11 commits intoAzure:mainfrom
vincenttran-msft:vincenttran/promote_download

Conversation

@vincenttran-msft
Copy link
Copy Markdown
Member

@vincenttran-msft vincenttran-msft commented Mar 31, 2026

Replaces BlobClient::download() with managed_download and the same exercise for download_into.

Summary

Promotes the managed (multi-part) download implementation to be the sole download() API on BlobClient, and adds download_into() which writes directly into a caller-supplied buffer. Both APIs use parallel range requests under the hood and return structured result types with all service headers parsed out directly.

Breaking Changes

  • BlobClient::download() return type changed
    • Before: Result<AsyncResponse<BlobClientDownloadResult>>
    • After: Result<BlobClientDownloadResult> - all headers are fields on the result struct directly; no .await on the response wrapper needed
  • BlobClientDownloadResult is a new hand-written struct with a body: AsyncResponseBody field plus a properties: BlobDownloadProperties field covering every header the Blob service returns (ETag, Content-Type, lease state, copy status, blob type, metadata, object-replication rules, etc.)
  • BlobClientDownloadResultHeaders trait removed — superseded by direct field access on BlobClientDownloadResult
  • range field type on BlobClientDownloadOptions changed
    • Before: Option<String>
    • After: Option<Range<usize>>
  • BlobClientManagedDownloadOptions renamed to BlobClientDownloadOptions
  • BlockBlobClient::download() and BlockBlobClientDownloadBehavior removed - download belongs on BlobClient

Changes

sdk/storage/azure_storage_blob

  • src/clients/blob_client.rs
    • BlobClient::download() now owns the full managed (multi-part) download implementation via BlobClientDownloadBehavior and the DEFAULT_DOWNLOAD_PARALLEL / DEFAULT_DOWNLOAD_PARTITION_SIZE constants
    • BlobClient::download_into() added - writes blob content directly into a caller-provided &mut [u8] buffer using the same partitioned transfer engine
  • src/clients/block_blob_client.rs
    • Removed BlockBlobClient::download(), BlockBlobClientDownloadBehavior, and all download-related imports
  • src/models/download_result.rs (new file)
    • Hand-written BlobClientDownloadResult with body, properties, and headers fields
    • BlobDownloadProperties covers every header returned by the Blob service
    • BlobClientDownloadResult::from_headers(AsyncRawResponse) handles all header parsing in one place
  • src/models/method_options.rs
    • Renamed BlobClientManagedDownloadOptions --> BlobClientDownloadOptions
  • src/models/mod.rs
    • Exports BlobClientDownloadResult, BlobDownloadProperties, and BlobClientDownloadOptions
  • src/parsers.rs
    • Added pub(crate) fn parse_metadata_and_replication_headers(headers) - extracts x-ms-meta-* and x-ms-or-* headers into reusable maps
  • src/partitioned_transfer/download.rs
    • Return type of internal download() changed to AzureResult<AsyncRawResponse> - surfaces the initial range-response headers without wrapping them in a misleading empty-body RawResponse
    • Internal unit tests updated to match

Tests

Updated the following integration test files to use direct field access on BlobClientDownloadResult:

  • tests/blob_client.rs
  • tests/blob_client_options.rs
  • tests/blob_client_snapshot.rs
  • tests/blob_client_versioning.rs
  • tests/blob_cpk.rs
  • tests/block_blob_client.rs
  • tests/append_blob_client.rs
  • tests/page_blob_client.rs
  • tests/streaming.rs

Copilot AI review requested due to automatic review settings March 31, 2026 07:57
@github-actions github-actions bot added Azure.Core The azure_core crate Storage Storage Service (Queues, Blobs, Files) labels Mar 31, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR promotes the managed, partitioned (multi-part) download implementation to be the default download() API on BlobClient and adds a new BlockBlobClient::download() that returns a hand-written download result type containing both the body stream and extracted response headers/metadata.

Changes:

  • Replaced the old single-shot BlobClient::download() (returning AsyncResponse<...>) with a managed download that returns a new BlobClientDownloadResult directly (alias of BlockBlobClientDownloadResult).
  • Updated partitioned download internals to return (RawResponse, PinnedStream) so callers can surface headers while streaming the body.
  • Updated tests and examples to use the new result type shape (.body, .raw_response, and direct header fields).

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/storage/azure_storage_blob/src/clients/block_blob_client.rs Adds BlockBlobClient::download() managed download implementation, behavior adapter, and header extraction into the new result type.
sdk/storage/azure_storage_blob/src/clients/blob_client.rs Switches BlobClient::download() to delegate to BlockBlobClient::download() and removes the old managed download implementation from BlobClient.
sdk/storage/azure_storage_blob/src/partitioned_transfer/download.rs Changes partitioned download to return (RawResponse, PinnedStream) and adjusts tests accordingly.
sdk/storage/azure_storage_blob/src/models/download_result.rs Introduces BlockBlobClientDownloadResult holding stream + extracted headers/metadata + RawResponse.
sdk/storage/azure_storage_blob/src/models/mod.rs Wires in the new download_result module and re-exports new result/options aliases.
sdk/storage/azure_storage_blob/src/models/method_options.rs Renames BlobClientManagedDownloadOptions to BlockBlobClientDownloadOptions and updates docs.
sdk/storage/azure_storage_blob/tests/streaming.rs Updates streaming tests to consume the new download result (.body, .raw_response).
sdk/storage/azure_storage_blob/tests/page_blob_client.rs Updates page blob tests to the new download return type.
sdk/storage/azure_storage_blob/tests/block_blob_client.rs Updates block blob tests to the new download return type.
sdk/storage/azure_storage_blob/tests/blob_cpk.rs Updates CPK-related download usages to the new return type.
sdk/storage/azure_storage_blob/tests/blob_client.rs Updates blob client integration tests (incl. managed download tests) to the new API surface.
sdk/storage/azure_storage_blob/tests/blob_client_versioning.rs Updates versioning tests to use the new download result.
sdk/storage/azure_storage_blob/tests/blob_client_snapshot.rs Updates snapshot tests to use the new download result.
sdk/storage/azure_storage_blob/tests/blob_client_options.rs Updates options tests to use the new download result.
sdk/storage/azure_storage_blob/tests/append_blob_client.rs Updates append blob tests to use the new download result.
sdk/storage/azure_storage_blob/examples/blob_storage_logging.rs Updates example to collect from response.body directly.
sdk/storage/azure_storage_blob/CHANGELOG.md Documents the download API breaking changes for the crate.
sdk/core/typespec_client_core/src/http/response.rs Makes AsyncResponseBody::new public to allow constructing bodies from PinnedStream across crates.
sdk/core/typespec_client_core/src/http/mod.rs Re-exports AsyncResponseBody from the http module.
sdk/core/azure_core/src/http/mod.rs Re-exports AsyncResponseBody from azure_core::http.

Copy link
Copy Markdown
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncResponse should not be publicly creatable. We can explore other options.

@vincenttran-msft vincenttran-msft requested a review from heaths April 1, 2026 20:43
@vincenttran-msft vincenttran-msft changed the title [Storage] Promote managed_download to be ubiquitous download API [Storage] Finalized managed_download and managed_download_to drop-in replacements Apr 3, 2026
Copy link
Copy Markdown
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to sdk/core approved. Good catch. I'm surprised our linter didn't complain since it's in a public API but, then again, types you return don't technically have to: this happens in a couple places I've seen in tokio.

@vincenttran-msft vincenttran-msft merged commit 0f206f6 into Azure:main Apr 4, 2026
17 checks passed
@vincenttran-msft vincenttran-msft deleted the vincenttran/promote_download branch April 4, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core The azure_core crate Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants