<commit_before>use std::path::{Path, PathBuf};
use std::io::{Result, Write};
use std::fs::{File, create_dir_all};

pub trait Output {
    fn get_writer(&self, &Path) -> Result<Box<Write>>;
}

pub struct FsOutput {
    pub root: PathBuf,
}

impl Output for FsOutput {
    fn get_writer(&self, path: &Path) -> Result<Box<Write>> {
        assert!(path.is_relative());
        let file_path = self.root.join(&path);
        if let Some(parent) = file_path.parent() {
            create_dir_all(parent.as_os_str())?;
        }
        let file = File::create(file_path.as_os_str())?;
        Ok(Box::new(file))
    }
}<commit_msg>Pass paths instead of OS strings to fs functions<commit_after>use std::path::{Path, PathBuf};
use std::io::{Result, Write};
use std::fs::{File, create_dir_all};

pub trait Output {
    fn get_writer(&self, &Path) -> Result<Box<Write>>;
}

pub struct FsOutput {
    pub root: PathBuf,
}

impl Output for FsOutput {
    fn get_writer(&self, path: &Path) -> Result<Box<Write>> {
        assert!(path.is_relative());
        let file_path = self.root.join(&path);
        if let Some(parent) = file_path.parent() {
            create_dir_all(parent)?;
        }
        let file = File::create(file_path.as_path())?;
        Ok(Box::new(file))
    }
}
{'fraction_non_alphanumeric': 0.16417910447761194, 'fraction_numerical': 0.0, 'mean_word_length': 3.2751677852348995, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '1247807', 'n_tokens_mistral': 430, 'n_tokens_neox': 438, 'n_words': 96}