本文整理匯總了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();
}
}
}