<commit_before><?php

/**
 * A wrapper around a php stream
 */
class Facade_Stream
{
	private $_stream;
	private $_length;
	private $_offset;
	private $_writable;

	/**
	 * Constructor
	 */
	public function __construct($stream, $length=null, $writable=false)
	{
		$this->_stream = $stream;
		$this->_offset = ftell($stream);
		$this->_length = $length;
		$this->_writable = $writable;
	}

	/**
	 * Closes the stream
	 */
	public function close()
	{
		fclose($this->_stream);
	}

	/**
	 * Reads $bytes from the stream
	 */
	public function read($bytes=1024)
	{
		$r = fread($this->_stream, $bytes);

		// check for errors
		if($errorcode = socket_last_error())
		{
			throw new Facade_StreamException("Socket error: $errormsg",
				socket_strerror($errorcode));
		}

		return $r;
	}

	/**
	 * Writes $data to the stream
	 * @return the number of bytes actually written
	 */
	public function write($data)
	{
		if(!$this->_writable)
		{
			throw new Facade_StreamException("Stream is not writable");
		}

		return fwrite($this->_stream, $data);
	}

	/**
	 * Rewinds the stream
	 */
	public function rewind()
	{
		rewind($this->_stream);
	}

	/**<commit_msg>Fixed undefined variable for socket error<commit_after><?php

/**
 * A wrapper around a php stream
 */
class Facade_Stream
{
	private $_stream;
	private $_length;
	private $_offset;
	private $_writable;

	/**
	 * Constructor
	 */
	public function __construct($stream, $length=null, $writable=false)
	{
		$this->_stream = $stream;
		$this->_offset = ftell($stream);
		$this->_length = $length;
		$this->_writable = $writable;
	}

	/**
	 * Closes the stream
	 */
	public function close()
	{
		fclose($this->_stream);
	}

	/**
	 * Reads $bytes from the stream
	 */
	public function read($bytes=1024)
	{
		$r = fread($this->_stream, $bytes);

		// check for errors
		if($errorcode = socket_last_error())
		{
			$errormsg = socket_strerror($errorcode);
			throw new Facade_StreamException("Socket error: $errormsg",
				socket_strerror($errorcode));
		}

		return $r;
	}

	/**
	 * Writes $data to the stream
	 * @return the number of bytes actually written
	 */
	public function write($data)
	{
		if(!$this->_writable)
		{
			throw new Facade_StreamException("Stream is not writable");
		}

		return fwrite($this->_stream, $data);
	}

	/**
	 * Rewinds the stream
	 */
	public function rewind()
	{
		rewind($this->_stream);
	}

	/**
{'fraction_non_alphanumeric': 0.15294117647058825, 'fraction_numerical': 0.0033613445378151263, 'mean_word_length': 3.475563909774436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '5077064', 'n_tokens_mistral': 899, 'n_tokens_neox': 802, 'n_words': 195}