当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlob.OpenRead方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:higheredgrowth,项目名称:lokad-cqrs,代码行数:35,代码来源:BlobStorageUtil.cs

示例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();
                }
            }
        }
开发者ID:robertogg,项目名称:Demos,代码行数:28,代码来源:LogFetcher.cs


注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlob.OpenRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。