本文介绍了CloudBlockBlob的OpenReadAsync和DownloadFromStreamAsync函数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure Blob存储中CloudBlockBlobOpenReadAsyncDownloadToStreamAsync函数之间有什么区别?在Google中搜索,但找不到答案.

What is the difference between OpenReadAsync and DownloadToStreamAsync functions of CloudBlockBlob in the Azure blob storage? Searched in google but could not find an answer.

推荐答案

OpenReadAsync和DownloadToStreamAsync都可以为您启动异步操作来检索blob流.根据我的测试,以下几节将使您对它们有更好的了解:

Both OpenReadAsync and DownloadToStreamAsync could initiate an asynchronous operation for you to retrieve the blob stream.Based on my testing, you could have a better understanding of them by the following sections: 

DownloadToStreamAsync:发起异步操作以将Blob的内容下载到流中.

DownloadToStreamAsync:Initiates an asynchronous operation to download the contents of a blob to a stream.

OpenReadAsync:启动异步操作以将Blob的内容下载到流中.

OpenReadAsync:Initiates an asynchronous operation to download the contents of a blob to a stream. 

a)DownloadToStreamAsync

a) DownloadToStreamAsync

示例代码:

using (var fs = new FileStream(<yourLocalFilePath>, FileMode.Create))
{
    await blob.DownloadToStreamAsync(fs);
}

b)OpenReadAsync

 b) OpenReadAsync

示例代码:

//Set buffer for reading from a blob stream, the default value is 4MB.
blob.StreamMinimumReadSizeInBytes=10*1024*1024; //10MB
using (var blobStream = await blob.OpenReadAsync())
{
    using (var fs = new FileStream(localFile, FileMode.Create))
    {   
       await blobStream.CopyToAsync(fs);
    }
}

通过Fiddler捕获网络请求

a)DownloadToStreamAsync

Capturing Network requests via Fiddler

a) DownloadToStreamAsync

b)OpenReadAsync

 b) OpenReadAsync

根据以上内容,DownloadToStreamAsync仅发送一个get请求以检索blob流,而OpenReadAsync根据您设置或默认值为"Blob.StreamMinimumReadSizeInBytes"发送多个请求以检索blob流.

 According to the above, DownloadToStreamAsync just sends one get request for retrieving blob stream, while OpenReadAsync sends more than one request to retrieving blob stream based on the "Blob.StreamMinimumReadSizeInBytes" you have set or by default value.

这篇关于CloudBlockBlob的OpenReadAsync和DownloadFromStreamAsync函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:36