<commit_before><?php
namespace wapmorgan\UnifiedArchive\Formats;

use Exception;
use wapmorgan\UnifiedArchive\ArchiveEntry;
use wapmorgan\UnifiedArchive\ArchiveInformation;
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedOperationException;

class Rar extends BasicFormat
{
    /** @var \RarArchive */
    protected $rar;

    /**
     * BasicFormat constructor.
     *
     * @param string $archiveFileName
     *
     * @throws \Exception
     */
    public function __construct($archiveFileName)
    {
        \RarException::setUsingExceptions(true);
        $this->open($archiveFileName);
    }

    /**
     * @param $archiveFileName
     *
     * @throws \Exception
     */
    protected function open($archiveFileName)
    {
        $this->rar = \RarArchive::open($archiveFileName);
        if ($this->rar === false) {
            throw new Exception('Could not open Rar archive');
        }
    }

    /**
     * Rar format destructor
     */
    public function __destruct()
    {
        $this->rar->close();
    }

    /**
     * @return ArchiveInformation
     */
    public function getArchiveInformation()
    {
        $information = new ArchiveInformation();
        foreach ($this->rar->getEntries() as $i => $entry) {
            $information->files[] = $entry->getName();
            $information->compressedFilesSize += $entry->getPackedSize();
            $information->uncompressedFilesSize += $entry->getUnpackedSize();
        }
        return $information;
    }

    /**
     * @return array
     */
    public function getFileNames()
    {
        $files = [];
        foreach ($this->rar->getEntries() as $i => $entry) {
            $files[] = $entry->getName();
        }
        return $files;
    }

    /**
     * @param string $fileName
     *
     * @return bool
     */
    public function isFileExists($fileName)
    {
        return $this->rar->getEntry($fileName) !== false;
    }

    /**
     * @param string $fileName
     *
     * @return ArchiveEntry|false
     */
    public function getFileData($fileName)
    {
        $entry = $this->rar->getEntry($fileName);
        return new ArchiveEntry($fileName, $entry->getPackedSize(), $entry->getUnpackedSize(),
            strtotime($entry->getFileTime()), $entry->getMethod() != 48);<commit_msg>Fixing #18: skip directories in rar<commit_after><?php
namespace wapmorgan\UnifiedArchive\Formats;

use Exception;
use wapmorgan\UnifiedArchive\ArchiveEntry;
use wapmorgan\UnifiedArchive\ArchiveInformation;
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedOperationException;

class Rar extends BasicFormat
{
    /** @var \RarArchive */
    protected $rar;

    /**
     * BasicFormat constructor.
     *
     * @param string $archiveFileName
     *
     * @throws \Exception
     */
    public function __construct($archiveFileName)
    {
        \RarException::setUsingExceptions(true);
        $this->open($archiveFileName);
    }

    /**
     * @param $archiveFileName
     *
     * @throws \Exception
     */
    protected function open($archiveFileName)
    {
        $this->rar = \RarArchive::open($archiveFileName);
        if ($this->rar === false) {
            throw new Exception('Could not open Rar archive');
        }
    }

    /**
     * Rar format destructor
     */
    public function __destruct()
    {
        $this->rar->close();
    }

    /**
     * @return ArchiveInformation
     */
    public function getArchiveInformation()
    {
        $information = new ArchiveInformation();
        foreach ($this->rar->getEntries() as $i => $entry) {
            if ($entry->isDirectory()) continue;
            $information->files[] = $entry->getName();
            $information->compressedFilesSize += $entry->getPackedSize();
            $information->uncompressedFilesSize += $entry->getUnpackedSize();
        }
        return $information;
    }

    /**
     * @return array
     */
    public function getFileNames()
    {
        $files = [];
        foreach ($this->rar->getEntries() as $i => $entry) {
            if ($entry->isDirectory()) continue;
            $files[] = $entry->getName();
        }
        return $files;
    }

    /**
     * @param string $fileName
     *
     * @return bool
     */
    public function isFileExists($fileName)
    {
        return $this->rar->getEntry($fileName) !== false;
    }

    /**
     * @param string $fileName
     *
     * @return ArchiveEntry|false
     */
    public function getFileData($fileName)
    {
        $entry = $this->rar->getEntry($fileName);
        return new ArchiveEntry($fileName, $entry->getPackedSize(), $entry->getUnpackedSize(),
            strtotime($entry->getFileTime()), $entry->getMethod() != 48);
{'fraction_non_alphanumeric': 0.14, 'fraction_numerical': 0.001276595744680851, 'mean_word_length': 2.2874125874125872, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '7107671', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1319, 'n_words': 254}