Example #1
0
 /// <summary>
 ///     Reads a sub-range from the specified <paramref name="blob"/> into <see cref="_buffer"/>.
 /// </summary>
 /// <returns>
 ///      Total bytes read, may be smaller than requested, but only if there were
 ///      not enough bytes in the blob.
 /// </returns>
 private static async Task <int> ReadSubRangeAsync(
     CloudAppendBlob blob,
     byte[] buffer,
     long start,
     int bufferStart,
     long maxBytes,
     CancellationToken cancel)
 {
     while (true)
     {
         try
         {
             return(await blob.DownloadRangeToByteArrayAsync(
                        buffer,
                        bufferStart,
                        start,
                        maxBytes,
                        new AccessCondition(),
                        new BlobRequestOptions(),
                        new OperationContext(),
                        cancel));
         }
         catch (StorageException e) when(e.Message.StartsWith("Incorrect number of bytes received."))
         {
             // Due to a miscommunication between the Azure servers for Append Blob and the
             // .NET client library, some responses are garbled due to a race condition out
             // of our control. We retry straight away, as the problem is rarely present
             // too many times in a row.
             //
             // See also: https://github.com/Azure/azure-storage-net/issues/366
         }
     }
 }
Example #2
0
        public int Read(out byte[] buffer, int offset, int count)
        {
            var bytes = new byte[count];
            var task  = blob.DownloadRangeToByteArrayAsync(bytes, 0, offset, count);

            buffer = bytes;

            return(task.Result);
        }