<commit_before>use std::io::BufferedReader;
use std::io::BufferedWriter;
use std::io::TcpStream;

struct IrcStream {
    inputstream: BufferedReader<TcpStream>,
    outputstream: BufferedWriter<TcpStream>,
    socket: TcpStream
}

impl IrcStream {
    pub fn new(host: &str, port: u16) -> IrcStream {
        let mut socket = TcpStream::connect((host, port)).unwrap();
        let mut reader = BufferedReader::new(socket.clone());
        let mut writer = BufferedWriter::new(socket.clone());        
        let mut stream = IrcStream{ inputstream: reader, outputstream: writer, socket: socket };        
        return stream;
    }
    
    pub fn read(&mut self) {
        loop {
            let next = self.inputstream.read_line();
            if next.is_err() {
                break;
            }
            let text = next.unwrap();
            print!("{}", text);
            if text.starts_with("ERROR") {
                break;
            }
            if text.starts_with("PING") {
                let pong = text.replace("PING ", "PONG ");
                self.write(pong.deref());
            }
        }
    }
    
    pub fn write(&mut self, line: &str) {
        print!("Writing: {}", line);
        self.outputstream.write_line(line);
        self.outputstream.flush();
    }
    
}<commit_msg>Adds comment.<commit_after>use std::io::BufferedReader;
use std::io::BufferedWriter;
use std::io::TcpStream;

struct IrcStream {
    inputstream: BufferedReader<TcpStream>,
    outputstream: BufferedWriter<TcpStream>,
    socket: TcpStream
}

impl IrcStream {
    pub fn new(host: &str, port: u16) -> IrcStream {
        let mut socket = TcpStream::connect((host, port)).unwrap();
        let mut reader = BufferedReader::new(socket.clone());
        let mut writer = BufferedWriter::new(socket.clone());        
        let mut stream = IrcStream{ inputstream: reader, outputstream: writer, socket: socket };        
        return stream;
    }
    
    pub fn read(&mut self) {
        loop {
            let next = self.inputstream.read_line();
            if next.is_err() {
                break;
            }
            let text = next.unwrap();
            print!("{}", text);
            if text.starts_with("ERROR") {
                break;
            }
            if text.starts_with("PING") {
                let pong = text.replace("PING ", "PONG ");
                self.write(pong.deref());
            }
        }
    }
    
    pub fn write(&mut self, line: &str) {
        print!("Writing: {}", line);
        self.outputstream.write_line(line);
        self.outputstream.flush(); // Maybe this shouldn't be a buffered output stream...?
    }
    
}
{'fraction_non_alphanumeric': 0.1325390915860015, 'fraction_numerical': 0.0014892032762472078, 'mean_word_length': 1.9238302502720348, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1645259', 'n_tokens_mistral': 795, 'n_tokens_neox': 783, 'n_words': 177}