<commit_before>﻿namespace Nine.Formatting
{
    using System.IO;
    using System.Text;

    public static class FormatterExtensions
    {
        private static readonly Encoding _encoding = new UTF8Encoding(false, true);

        public static T ReadFrom<T>(this IFormatter formatter, Stream stream)
        {
            return (T)formatter.ReadFrom(typeof(T), stream);
        }

        public static T ReadFrom<T>(this ITextFormatter formatter, Stream stream)
        {
            using (var reader = new StreamReader(stream, _encoding, true, 1024, leaveOpen: true))
            {
                return (T)formatter.ReadFrom(typeof(T), new StreamReader(stream));
            }
        }

        public static void WriteTo<T>(this ITextFormatter formatter, T value, Stream stream)
        {
            using (var writer = new StreamWriter(stream, _encoding, 1024, leaveOpen: true))
            {
                formatter.WriteTo(value, writer);
            }
        }

        public static T FromText<T>(this ITextFormatter formatter, string text)
        {
            return (T)formatter.ReadFrom(typeof(T), new StringReader(text));
        }

        public static string ToText(this ITextFormatter formatter, object value)
        {
            var sb = StringBuilderCache.Acquire(256);
            formatter.WriteTo(value, new StringWriter(sb));
            return StringBuilderCache.GetStringAndRelease(sb);
        }
    }
}<commit_msg>ReadFrom(type)<commit_after>﻿namespace Nine.Formatting
{
    using System;
    using System.IO;
    using System.Text;

    public static class FormatterExtensions
    {
        private static readonly Encoding s_encoding = new UTF8Encoding(false, true);

        public static T ReadFrom<T>(this IFormatter formatter, Stream stream)
        {
            return (T)formatter.ReadFrom(typeof(T), stream);
        }

        public static T ReadFrom<T>(this ITextFormatter formatter, Stream stream)
        {
            using (var reader = new StreamReader(stream, s_encoding, true, 1024, leaveOpen: true))
            {
                return (T)formatter.ReadFrom(typeof(T), new StreamReader(stream));
            }
        }

        public static object ReadFrom(this ITextFormatter formatter, Type type, Stream stream)
        {
            using (var reader = new StreamReader(stream, s_encoding, true, 1024, leaveOpen: true))
            {
                return formatter.ReadFrom(type, new StreamReader(stream));
            }
        }

        public static void WriteTo(this ITextFormatter formatter, object value, Stream stream)
        {
            using (var writer = new StreamWriter(stream, s_encoding, 1024, leaveOpen: true))
            {
                formatter.WriteTo(value, writer);
            }
        }

        public static T FromText<T>(this ITextFormatter formatter, string text)
        {
            return (T)formatter.ReadFrom(typeof(T), new StringReader(text));
        }

        public static string ToText(this ITextFormatter formatter, object value)
        {
            var sb = StringBuilderCache.Acquire(256);
            formatter.WriteTo(value, new StringWriter(sb));
            return StringBuilderCache.GetStringAndRelease(sb);
        }
    }
}
{'fraction_non_alphanumeric': 0.08610086100861009, 'fraction_numerical': 0.008610086100861008, 'mean_word_length': 2.214426877470356, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3104791', 'n_tokens_mistral': 873, 'n_tokens_neox': 816, 'n_words': 226}