OpenRead() публичный Метод

Opens a stream for reading the blob's contents.
public OpenRead ( ) : Microsoft.WindowsAzure.StorageClient.BlobStream
Результат Microsoft.WindowsAzure.StorageClient.BlobStream
Пример #1
0
        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
0
        /// <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();
                }
            }
        }