本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.OpenRead方法的具体用法?C# CloudBlob.OpenRead怎么用?C# CloudBlob.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.StorageClient.CloudBlob
的用法示例。
在下文中一共展示了CloudBlob.OpenRead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public static void Read(BlobRequestOptions mapped, CloudBlob blob, ReaderDelegate reader)
{
blob.FetchAttributes(mapped);
var props = MapFetchedAttrbitues(blob);
var compression = blob.Properties.ContentEncoding ?? "";
var md5 = blob.Metadata[LokadHashFieldName];
switch (compression)
{
case "gzip":
using (var stream = blob.OpenRead(mapped))
{
ReadAndVerifyHash(stream, s =>
{
// important is not to flush the decompression stream
using (var decompress = new GZipStream(s, CompressionMode.Decompress, true))
{
reader(props, decompress);
}
}, md5);
}
break;
case "":
using (var stream = blob.OpenRead(mapped))
{
ReadAndVerifyHash(stream, s => reader(props, s), md5);
}
break;
default:
var error = string.Format("Unsupported ContentEncoding '{0}'", compression);
throw new InvalidOperationException(error);
}
}
示例2: CopyContents
/// <summary>
/// Copies the full binary contents of the given blob to the given HTTP response.
/// </summary>
private static void CopyContents(CloudBlob blob, HttpResponseBase response, long offset = 0)
{
blob.FetchAttributes();
response.BufferOutput = false;
response.AddHeader("Content-Length", blob.Attributes.Properties.Length.ToString());
response.Flush();
using (var reader = blob.OpenRead())
{
reader.Seek(offset, System.IO.SeekOrigin.Begin);
byte[] buffer = new byte[1024 * 4]; // 4KB buffer
while (reader.CanRead)
{
int numBytes = reader.Read(buffer, 0, buffer.Length);
if (numBytes <= 0)
break;
response.BinaryWrite(buffer);
response.Flush();
}
}
}