<commit_before><?php

namespace BigFileTools\Driver;
use Brick\Math\BigInteger;

class ExecDriver implements ISizeDriver
{
	public function __construct()
	{
		if (!function_exists("exec")) {
			throw new PrerequisiteException("Exec function is disabled");
		}
	}

	/**
	 * Returns file size by using system shell/cmd commands
	 * @inheritdoc
	 * @link http://stackoverflow.com/questions/5501451/php-x86-how-to-get-filesize-of-2gb-file-without-external-program/5502328#5502328
	 */
	public function getFileSize($path)
	{


		$escapedPath = escapeshellarg($path);

		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { // Windows
			// Try using the NT substitution modifier %~z
			$size = trim(exec("for %F in ($escapedPath) do @echo %~zF"));
		}else{ // other OS
			// If the platform is not Windows, use the stat command (should work for *nix and MacOS)
			$size = trim(exec("stat -Lc%s $escapedPath"));
		}

		// If the return is not blank, not zero, and is number
		if ($size AND ctype_digit($size)) {
			return BigInteger::of($size);
		} else {
			throw new Exception("Exec returned invalid value");
		}
	}
}<commit_msg>ExecDriver: refactored and fixed bug on Mac OS X<commit_after><?php

namespace BigFileTools\Driver;
use Brick\Math\BigInteger;

class ExecDriver implements ISizeDriver
{
	private $os;
	const OS_WINDOWS = "Windows";
	const OS_LINUX = "Linux";
	const OS_MAC = "Mac";

	public function __construct()
	{
		if (!function_exists("exec")) {
			throw new PrerequisiteException("Exec function is disabled");
		}

		if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
			$this->os = self::OS_WINDOWS;
		} elseif (strtoupper(PHP_OS) == "DARWIN") {
			$this->os = self::OS_MAC;
		} else {
			$this->os = self::OS_LINUX;
		}
	}

	/**
	 * Returns file size by using system shell/cmd commands
	 * @inheritdoc
	 * @link http://stackoverflow.com/questions/5501451/php-x86-how-to-get-filesize-of-2gb-file-without-external-program/5502328#5502328
	 * @return BigInteger
	 */
	public function getFileSize($path)
	{
		switch($this->os) {
			case self::OS_WINDOWS: return $this->getFileSizeWindows($path); break;
			case self::OS_LINUX:   return $this->getFileSizeLinux($path); break;
			case self::OS_MAC:     return $this->getFileSizeMac($path); break;
			default: throw new Exception("OS not detected");
		}
	}

	private function getFileSizeWindows($path)
	{
		$escapedPath = escapeshellarg($path);
		$size = trim(exec("for %F in ($escapedPath) do @echo %~zF"));
		if ($size AND ctype_digit($size)) {
			return BigInteger::of($size);
		} else {
			throw new Exception("Exec returned invalid value");
		}
	}

	private function getFileSizeLinux($path)
	{
		$escapedPath = escapeshellarg($path);
		$size = trim(exec("stat -Lc%s $escapedPath"));
		if ($size AND ctype_digit($size)) {
			return BigInteger::of($size);
		} else {
			throw new Exception("Exec returned invalid value");
		}
	}

	private function getFileSizeMac($path)
	{
		$escapedPath = escapeshellarg($path);
		$size = trim(exec("stat -f%z $escapedPath"));
		if ($size AND ctype_digit($size)) {
			return BigInteger::of($size);
		} else {
			throw new Exception("Exec returned invalid value");
		}
	}
}
{'fraction_non_alphanumeric': 0.14773805757671624, 'fraction_numerical': 0.016450490351154697, 'mean_word_length': 4.192118226600985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '5077894', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1064, 'n_words': 265}