From ed8fce2dced5aa1e3db5426e2bdd0aaf756d0e6b Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 8 Jan 2021 23:03:02 +0100 Subject: Use SubtitleEdit to parse subtitles --- MediaBrowser.Common/Extensions/StreamExtensions.cs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 MediaBrowser.Common/Extensions/StreamExtensions.cs (limited to 'MediaBrowser.Common/Extensions/StreamExtensions.cs') diff --git a/MediaBrowser.Common/Extensions/StreamExtensions.cs b/MediaBrowser.Common/Extensions/StreamExtensions.cs new file mode 100644 index 000000000..cd77be7b2 --- /dev/null +++ b/MediaBrowser.Common/Extensions/StreamExtensions.cs @@ -0,0 +1,51 @@ +#nullable enable + +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace MediaBrowser.Common.Extensions +{ + /// + /// Class BaseExtensions. + /// + public static class StreamExtensions + { + /// + /// Reads all lines in the . + /// + /// The to read from. + /// All lines in the stream. + public static string[] ReadAllLines(this Stream stream) + => ReadAllLines(stream, Encoding.UTF8); + + /// + /// Reads all lines in the . + /// + /// The to read from. + /// The character encoding to use. + /// All lines in the stream. + public static string[] ReadAllLines(this Stream stream, Encoding encoding) + { + using (StreamReader reader = new StreamReader(stream, encoding)) + { + return ReadAllLines(reader).ToArray(); + } + } + + /// + /// Reads all lines in the . + /// + /// The to read from. + /// All lines in the stream. + public static IEnumerable ReadAllLines(this StreamReader reader) + { + string? line; + while ((line = reader.ReadLine()) != null) + { + yield return line; + } + } + } +} -- cgit v1.2.3