<commit_before>﻿#region

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Security.AccessControl;
using Containerizer.Properties;
using Containerizer.Services.Interfaces;
using IronFrame;

#endregion

namespace Containerizer.Services.Implementations
{
    public class TarStreamService : ITarStreamService
    {

        private static string TarArchiverPath(string filename)
        {
            var uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            return Path.Combine(Path.GetDirectoryName(uri.LocalPath), filename);
        }

        public TarStreamService()
        {
            File.WriteAllBytes(TarArchiverPath("tar.exe"), Resources.bsdtar);
            File.WriteAllBytes(TarArchiverPath("bzip2.dll"), Resources.bzip2);
            File.WriteAllBytes(TarArchiverPath("libarchive2.dll"), Resources.libarchive2);
            File.WriteAllBytes(TarArchiverPath("zlib1.dll"), Resources.zlib1);
        }

        public Stream WriteTarToStream(string filePath)
        {
            string tarPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".gz");
            CreateTarFromDirectory(filePath, tarPath);
            Stream stream = File.OpenRead(tarPath);
            var buffer = new byte[stream.Length];
            stream.Read(buffer, 0, (int)stream.Length);
            var memStream = new MemoryStream(buffer);
            stream.Close();
            File.Delete(tarPath);<commit_msg>Only copy resources to assembly path once<commit_after>﻿#region

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Security.AccessControl;
using Containerizer.Properties;
using Containerizer.Services.Interfaces;
using IronFrame;

#endregion

namespace Containerizer.Services.Implementations
{
    public class TarStreamService : ITarStreamService
    {

        private static string TarArchiverPath(string filename)
        {
            var uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            return Path.Combine(Path.GetDirectoryName(uri.LocalPath), filename);
        }

        static TarStreamService()
        {
            File.WriteAllBytes(TarArchiverPath("tar.exe"), Resources.bsdtar);
            File.WriteAllBytes(TarArchiverPath("bzip2.dll"), Resources.bzip2);
            File.WriteAllBytes(TarArchiverPath("libarchive2.dll"), Resources.libarchive2);
            File.WriteAllBytes(TarArchiverPath("zlib1.dll"), Resources.zlib1);
        }

        public Stream WriteTarToStream(string filePath)
        {
            string tarPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".gz");
            CreateTarFromDirectory(filePath, tarPath);
            Stream stream = File.OpenRead(tarPath);
            var buffer = new byte[stream.Length];
            stream.Read(buffer, 0, (int)stream.Length);
            var memStream = new MemoryStream(buffer);
            stream.Close();
            File.Delete(tarPath);
{'fraction_non_alphanumeric': 0.10026737967914438, 'fraction_numerical': 0.004679144385026738, 'mean_word_length': 3.01744966442953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5453255', 'n_tokens_mistral': 817, 'n_tokens_neox': 804, 'n_words': 151}