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

namespace osu_StreamCompanion.Code.Modules.MapDataGetters.FileMap
{
    public class FileMapManager
    {
        Dictionary<string, MapContainer> _files = new Dictionary<string, MapContainer>();
        private readonly object _lockingObject = new object();
        private class MapContainer
        {
            public MemoryMappedFile File { get; set; }
            private readonly object _lockingObject = new object();
            
            public void Write(string data)
            {
                lock (_lockingObject)
                {
                    var bytes = Encoding.Unicode.GetBytes(data);
                    using (var a = File.CreateViewStream())
                    {

                        a.Write(bytes, 0, bytes.Length);
                        a.WriteByte(0);
                    }
                }
            }
        }
        
        private MapContainer GetFile(string pipeName)<commit_msg>Add support for sending ASCII characters in FileMapManager<commit_after>﻿using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Text;

namespace osu_StreamCompanion.Code.Modules.MapDataGetters.FileMap
{
    public class FileMapManager
    {
        Dictionary<string, MapContainer> _files = new Dictionary<string, MapContainer>();
        private readonly object _lockingObject = new object();
        private class MapContainer
        {
            public MemoryMappedFile File { get; set; }
            public bool ASCIIonly = false;
            private readonly object _lockingObject = new object();

            public void Write(string data)
            {
                lock (_lockingObject)
                {
                    byte[] bytes;
                    if (ASCIIonly)
                        bytes = Encoding.ASCII.GetBytes(data.Replace("\\n","\n"));
                    else
                        bytes = Encoding.Unicode.GetBytes(data);
                    using (var a = File.CreateViewStream())
                    {
                        a.Write(bytes, 0, bytes.Length);
                        a.WriteByte(0);
                    }
                }
            }
        }

        private MapContainer GetFile(string pipeName)
{'fraction_non_alphanumeric': 0.07718405428329092, 'fraction_numerical': 0.0016963528413910093, 'mean_word_length': 1.5613463626492943, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1117975', 'n_tokens_mistral': 579, 'n_tokens_neox': 542, 'n_words': 136}