< Summary

Class:Azure.Core.Http.StreamHelperExtensions
Assembly:Azure.Storage.Blobs.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\StreamHelperExtensions.cs
Covered lines:10
Uncovered lines:5
Coverable lines:15
Total lines:55
Line coverage:66.6% (10 of 15)
Covered branches:1
Total branches:6
Branch coverage:16.6% (1 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
DrainAsync(...)-100%100%
DrainAsync(...)-100%100%
DrainAsync()-61.54%16.67%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\StreamHelperExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// Copied from https://github.com/aspnet/AspNetCore/tree/master/src/Http/WebUtilities/src
 5
 6using System.Buffers;
 7using System.IO;
 8using System.Threading;
 9using System.Threading.Tasks;
 10
 11#pragma warning disable IDE1006 // Prefix _ unexpected
 12
 13namespace Azure.Core.Http
 14{
 15    internal static class StreamHelperExtensions
 16    {
 17        private const int _maxReadBufferSize = 1024 * 4;
 18
 19        public static Task DrainAsync(this Stream stream, CancellationToken cancellationToken)
 20        {
 136021            return stream.DrainAsync(ArrayPool<byte>.Shared, null, cancellationToken);
 22        }
 23
 24        public static Task DrainAsync(this Stream stream, long? limit, CancellationToken cancellationToken)
 25        {
 8826            return stream.DrainAsync(ArrayPool<byte>.Shared, limit, cancellationToken);
 27        }
 28
 29        public static async Task DrainAsync(this Stream stream, ArrayPool<byte> bytePool, long? limit, CancellationToken
 30        {
 144831            cancellationToken.ThrowIfCancellationRequested();
 144832            var buffer = bytePool.Rent(_maxReadBufferSize);
 144833            long total = 0;
 34            try
 35            {
 144836                var read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
 144837                while (read > 0)
 38                {
 39                    // Not all streams support cancellation directly.
 040                    cancellationToken.ThrowIfCancellationRequested();
 041                    if (limit.HasValue && limit.GetValueOrDefault() - total < read)
 42                    {
 043                        throw new InvalidDataException($"The stream exceeded the data limit {limit.GetValueOrDefault()}.
 44                    }
 045                    total += read;
 046                    read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
 47                }
 144848            }
 49            finally
 50            {
 144851                bytePool.Return(buffer);
 52            }
 144853        }
 54    }
 55}