<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Bumpy.Util
{
    internal class FileUtil : IFileUtil
    {
        private const string _bumpyConfig = ".bumpyconfig";

        public IEnumerable<FileInfo> GetFiles(DirectoryInfo directory, string searchPattern)
        {
            directory.ThrowIfNull(nameof(directory));
            searchPattern.ThrowIfNull(nameof(searchPattern));

            return directory.GetFiles(searchPattern, SearchOption.AllDirectories);
        }

        public FileContent ReadFile(FileInfo file)
        {
            file.ThrowIfNull(nameof(file));

            using (var reader = new StreamReader(file.FullName))
            {
                var lines = new List<string>();
                string line = null;

                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                }

                var encoding = reader.CurrentEncoding;

                return new FileContent(file, lines, encoding);
            }
        }

        public void WriteFiles(IEnumerable<FileContent> content)
        {
            content.ThrowIfNull(nameof(content));

            foreach (var contentEntry in content)
            {
                contentEntry.ThrowIfNull(nameof(contentEntry));<commit_msg>Use EnumerateFiles instead of GetFiles<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Bumpy.Util
{
    internal class FileUtil : IFileUtil
    {
        private const string _bumpyConfig = ".bumpyconfig";

        public IEnumerable<FileInfo> GetFiles(DirectoryInfo directory, string searchPattern)
        {
            directory.ThrowIfNull(nameof(directory));
            searchPattern.ThrowIfNull(nameof(searchPattern));

            return directory.EnumerateFiles(searchPattern, SearchOption.AllDirectories);
        }

        public FileContent ReadFile(FileInfo file)
        {
            file.ThrowIfNull(nameof(file));

            using (var reader = new StreamReader(file.FullName))
            {
                var lines = new List<string>();
                string line = null;

                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                }

                var encoding = reader.CurrentEncoding;

                return new FileContent(file, lines, encoding);
            }
        }

        public void WriteFiles(IEnumerable<FileContent> content)
        {
            content.ThrowIfNull(nameof(content));

            foreach (var contentEntry in content)
            {
                contentEntry.ThrowIfNull(nameof(contentEntry));
{'fraction_non_alphanumeric': 0.08451730418943534, 'fraction_numerical': 0.0, 'mean_word_length': 1.9368983957219252, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5082403', 'n_tokens_mistral': 687, 'n_tokens_neox': 650, 'n_words': 145}