< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 92
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: TryReadAll(...)0%440%
File 1: GetAndValidateSize(...)0%880%
File 2: ReadExactly(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/StreamExtensions.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.IO;
 6using System.Runtime.InteropServices;
 7
 8namespace System.Reflection.Internal
 9{
 10    internal static partial class StreamExtensions
 11    {
 12        /// <summary>
 13        /// Attempts to read all of the requested bytes from the stream into the buffer
 14        /// </summary>
 15        /// <returns>
 16        /// The number of bytes read. Less than <paramref name="count" /> will
 17        /// only be returned if the end of stream is reached before all bytes can be read.
 18        /// </returns>
 19        /// <remarks>
 20        /// Unlike <see cref="Stream.Read(byte[], int, int)"/> it is not guaranteed that
 21        /// the stream position or the output buffer will be unchanged if an exception is
 22        /// returned.
 23        /// </remarks>
 24        internal static int TryReadAll(this Stream stream, byte[] buffer, int offset, int count)
 025        {
 26            // The implementations for many streams, e.g. FileStream, allows 0 bytes to be
 27            // read and returns 0, but the documentation for Stream.Read states that 0 is
 28            // only returned when the end of the stream has been reached. Rather than deal
 29            // with this contradiction, let's just never pass a count of 0 bytes
 030            Debug.Assert(count > 0);
 31
 32            int totalBytesRead;
 33            int bytesRead;
 034            for (totalBytesRead = 0; totalBytesRead < count; totalBytesRead += bytesRead)
 035            {
 36                // Note: Don't attempt to save state in-between calls to .Read as it would
 37                // require a possibly massive intermediate buffer array
 038                bytesRead = stream.Read(buffer,
 039                                        offset + totalBytesRead,
 040                                        count - totalBytesRead);
 041                if (bytesRead == 0)
 042                {
 043                    break;
 44                }
 045            }
 046            return totalBytesRead;
 047        }
 48
 49        /// <summary>
 50        /// Resolve image size as either the given user-specified size or distance from current position to end-of-strea
 51        /// Also performs the relevant argument validation and publicly visible caller has same argument names.
 52        /// </summary>
 53        /// <exception cref="ArgumentException">size is 0 and distance from current position to end-of-stream can't fit 
 54        /// <exception cref="ArgumentOutOfRangeException">Size is negative or extends past the end-of-stream from curren
 55        internal static int GetAndValidateSize(Stream stream, int size, string streamParameterName)
 056        {
 057            long maxSize = stream.Length - stream.Position;
 58
 059            if (size < 0 || size > maxSize)
 060            {
 061                throw new ArgumentOutOfRangeException(nameof(size));
 62            }
 63
 064            if (size != 0)
 065            {
 066                return size;
 67            }
 68
 069            if (maxSize > int.MaxValue)
 070            {
 071                throw new ArgumentException(SR.StreamTooLarge, streamParameterName);
 72            }
 73
 074            return (int)maxSize;
 075        }
 76    }
 77}
 78

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/StreamExtensions.netcoreapp.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.IO;
 5
 6namespace System.Reflection.Internal
 7{
 8    internal static partial class StreamExtensions
 9    {
 10        internal static unsafe void ReadExactly(this Stream stream, byte* buffer, int size)
 011            => stream.ReadExactly(new Span<byte>(buffer, size));
 12    }
 13}
 14