<commit_before>﻿#if NET45_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES
using System.IO;
using System.Text;
using System.Threading.Tasks;

using JetBrains.Annotations;

namespace CodeJam.IO
{
	/// <summary>
	/// Stream extensions.
	/// </summary>
	[PublicAPI]
	public static class StreamExtensions
	{
		private const int _defaultBufferSize = 1024;

		/// <summary>
		/// Wraps <paramref name="stream" /> with <see cref="StreamReader" />.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="StreamReader" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static StreamReader ToStreamReader(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
			new StreamReader(stream, encoding ?? Encoding.UTF8, true, _defaultBufferSize, leaveOpen);

		/// <summary>
		/// Wraps <paramref name="stream"/> with <see cref="BinaryReader"/>.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="BinaryReader" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static BinaryReader ToBinaryReader(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
			new BinaryReader(stream, encoding ?? Encoding.UTF8, leaveOpen);

		/// <summary>
		/// Wraps <paramrefref name="stream"/> with <see cref="StreamWriter"/>.
		/// </summary>
		/// <param name="stream">The stream to write.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="StreamWriter" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static StreamWriter ToStreamWriter(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
			new StreamWriter(stream, encoding ?? Encoding.UTF8, _defaultBufferSize, leaveOpen);

		/// <summary>
		/// Wraps <paramref name="stream"/> with <see cref="BinaryWriter"/>.
		/// </summary>
		/// <param name="stream">The stream to write.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="BinaryWriter" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static BinaryWriter ToBinaryWriter(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
				new BinaryWriter(stream, encoding ?? Encoding.UTF8, leaveOpen);

		/// <summary>
		/// Returns content of the stream as a byte array.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		[NotNull]
		public static string ReadAsString([NotNull] this Stream stream, [CanBeNull] Encoding encoding = null)
		{
			// DO NOT dispose the reader
			using (var reader = stream.ToStreamReader(encoding, true))
			{
				return reader.ReadToEnd();
			}
		}

		/// <summary>
		/// Returns content of the stream as a string.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		[NotNull]
		public static async Task<string> ReadAsStringAsync(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null)
		{
			// DO NOT dispose the reader
			using (var reader = stream.ToStreamReader(encoding, true))
			{
				return await reader.ReadToEndAsync().ConfigureAwait(false);
			}
		}
		/// <summary>
		/// Returns content of the stream as a byte array.<commit_msg>Minor cleanup<commit_after>﻿#if NET45_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;

using JetBrains.Annotations;

namespace CodeJam.IO
{
	/// <summary>
	/// Stream extensions.
	/// </summary>
	[PublicAPI]
	public static class StreamExtensions
	{
		private const int _defaultBufferSize = 1024;

		/// <summary>
		/// Wraps <paramref name="stream" /> with <see cref="StreamReader" />.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="StreamReader" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static StreamReader ToStreamReader(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
				new StreamReader(stream, encoding ?? Encoding.UTF8, true, _defaultBufferSize, leaveOpen);

		/// <summary>
		/// Wraps <paramref name="stream"/> with <see cref="BinaryReader"/>.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="BinaryReader" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static BinaryReader ToBinaryReader(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
				new BinaryReader(stream, encoding ?? Encoding.UTF8, leaveOpen);

		/// <summary>
		/// Wraps <paramref name="stream"/> with <see cref="StreamWriter"/>.
		/// </summary>
		/// <param name="stream">The stream to write.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="StreamWriter" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static StreamWriter ToStreamWriter(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
				new StreamWriter(stream, encoding ?? Encoding.UTF8, _defaultBufferSize, leaveOpen);

		/// <summary>
		/// Wraps <paramref name="stream"/> with <see cref="BinaryWriter"/>.
		/// </summary>
		/// <param name="stream">The stream to write.</param>
		/// <param name="encoding">The character encoding to use.</param>
		/// <param name="leaveOpen">true to leave the stream open after the <see cref="BinaryWriter" /> object is disposed; otherwise, false.</param>
		[NotNull]
		public static BinaryWriter ToBinaryWriter(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null,
			bool leaveOpen = false) =>
				new BinaryWriter(stream, encoding ?? Encoding.UTF8, leaveOpen);

		/// <summary>
		/// Returns content of the stream as a byte array.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		[NotNull]
		public static string ReadAsString([NotNull] this Stream stream, [CanBeNull] Encoding encoding = null)
		{
			// DO NOT dispose the reader
			using (var reader = stream.ToStreamReader(encoding, true))
			{
				return reader.ReadToEnd();
			}
		}

		/// <summary>
		/// Returns content of the stream as a string.
		/// </summary>
		/// <param name="stream">The stream to read.</param>
		/// <param name="encoding">The character encoding to use.</param>
		[NotNull]
		public static async Task<string> ReadAsStringAsync(
			[NotNull] this Stream stream,
			[CanBeNull] Encoding encoding = null)
		{
			// DO NOT dispose the reader
			using (var reader = stream.ToStreamReader(encoding, true))
			{
				return await reader.ReadToEndAsync().ConfigureAwait(false);
			}
		}

		/// <summary>
		/// Returns content of the stream as a byte array.
{'fraction_non_alphanumeric': 0.1440255591054313, 'fraction_numerical': 0.0025559105431309905, 'mean_word_length': 3.61438679245283, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4104720', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2248, 'n_words': 722}