< Summary - Jellyfin

Information
Class: Jellyfin.Extensions.StreamExtensions
Assembly: Jellyfin.Extensions
File(s): /srv/git/jellyfin/src/Jellyfin.Extensions/StreamExtensions.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 64
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ReadAllLines(...)100%11100%
ReadAllLines(...)100%11100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Extensions/StreamExtensions.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.IO;
 3using System.Linq;
 4using System.Runtime.CompilerServices;
 5using System.Text;
 6using System.Threading;
 7
 8namespace Jellyfin.Extensions
 9{
 10    /// <summary>
 11    /// Class BaseExtensions.
 12    /// </summary>
 13    public static class StreamExtensions
 14    {
 15        /// <summary>
 16        /// Reads all lines in the <see cref="Stream" />.
 17        /// </summary>
 18        /// <param name="stream">The <see cref="Stream" /> to read from.</param>
 19        /// <returns>All lines in the stream.</returns>
 20        public static string[] ReadAllLines(this Stream stream)
 521            => ReadAllLines(stream, Encoding.UTF8);
 22
 23        /// <summary>
 24        /// Reads all lines in the <see cref="Stream" />.
 25        /// </summary>
 26        /// <param name="stream">The <see cref="Stream" /> to read from.</param>
 27        /// <param name="encoding">The character encoding to use.</param>
 28        /// <returns>All lines in the stream.</returns>
 29        public static string[] ReadAllLines(this Stream stream, Encoding encoding)
 30        {
 531            using StreamReader reader = new StreamReader(stream, encoding);
 532            return ReadAllLines(reader).ToArray();
 533        }
 34
 35        /// <summary>
 36        /// Reads all lines in the <see cref="TextReader" />.
 37        /// </summary>
 38        /// <param name="reader">The <see cref="TextReader" /> to read from.</param>
 39        /// <returns>All lines in the stream.</returns>
 40        public static IEnumerable<string> ReadAllLines(this TextReader reader)
 41        {
 42            string? line;
 43            while ((line = reader.ReadLine()) is not null)
 44            {
 45                yield return line;
 46            }
 47        }
 48
 49        /// <summary>
 50        /// Reads all lines in the <see cref="TextReader" />.
 51        /// </summary>
 52        /// <param name="reader">The <see cref="TextReader" /> to read from.</param>
 53        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 54        /// <returns>All lines in the stream.</returns>
 55        public static async IAsyncEnumerable<string> ReadAllLinesAsync(this TextReader reader, [EnumeratorCancellation] 
 56        {
 57            string? line;
 58            while ((line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false)) is not null)
 59            {
 60                yield return line;
 61            }
 62        }
 63    }
 64}