<commit_before><?php

declare(strict_types=1);

namespace PBurggraf\BinaryUtilities;

use PBurggraf\BinaryUtilities\DataType\AbstractDataType;
use PBurggraf\BinaryUtilities\EndianType\AbstractEndianType;
use PBurggraf\BinaryUtilities\EndianType\BigEndian;
use PBurggraf\BinaryUtilities\Exception\DataTypeDoesNotExistsException;
use PBurggraf\BinaryUtilities\Exception\EndianTypeDoesNotExistsException;
use PBurggraf\BinaryUtilities\Exception\EndOfFileReachedException;
use PBurggraf\BinaryUtilities\Exception\FileDoesNotExistsException;
use PBurggraf\BinaryUtilities\Exception\InvalidDataTypeException;

/**
 * @author <NAME> <<EMAIL>>
 */
class BinaryUtilities
{
    const MODE_READ = 'read';
    const MODE_WRITE = 'write';

    const BASE_BINARY = 2;
    const BASE_OCTAL = 7;
    const BASE_DECIMAL = 10;
    const BASE_HEXADECIMAL = 16;

    /**
     * @var string
     */
    protected $file;

    /**
     * @var int
     */
    protected $currentMode;

    /**
     * @var string
     */
    protected $content;

    /**
     * @var int
     */
    protected $endOfFile;

    /**
     * @var int
     */
    protected $base = self::BASE_DECIMAL;

    /**
     * @var array
     */
    protected $buffer = [];

    /**
     * @var int
     */
    protected $currentBit;

    /**
     * @var int
     */
    protected $offset = 0;

    /**
     * @var string
     */
    protected $endian;

    /**
     * @var AbstractDataType[]
     */
    protected $dataTypeClasses = [];

    /**
     * @param string $file
     *
     * @throws FileDoesNotExistsException
     *
     * @return BinaryUtilities
     */
    public function setFile(string $file): BinaryUtilities
    {
        if (!file_exists($file)) {
            throw new FileDoesNotExistsException();
        }
        $this->file = $file;
        $this->setContent();

        return $this;
    }

    /**
     * @param string $mode
     *
     * @return BinaryUtilities
     */
    public function setEndian(string $mode): BinaryUtilities
    {
        $this->endian = $mode;

        return $this;
    }

    /**
     * @param int $offset
     *
     * @throws EndOfFileReachedException
     *
     * @return BinaryUtilities
     */
    public function offset(int $offset): BinaryUtilities
    {
        $this->offset = $offset;

        return $this;
    }

    /**
     * @param int $base
     *
     * @return BinaryUtilities
     */
    public function setBase(int $base = self::BASE_DECIMAL): BinaryUtilities
    {
        $this->base = $base;

        return $this;
    }

    /**
     * @return array
     */
    public function returnBuffer(): array
    {
        return array_map([$this, 'convertToBase'], $this->buffer);
    }<commit_msg># able to clear buffer after return it<commit_after><?php

declare(strict_types=1);

namespace PBurggraf\BinaryUtilities;

use PBurggraf\BinaryUtilities\DataType\AbstractDataType;
use PBurggraf\BinaryUtilities\EndianType\AbstractEndianType;
use PBurggraf\BinaryUtilities\EndianType\BigEndian;
use PBurggraf\BinaryUtilities\Exception\DataTypeDoesNotExistsException;
use PBurggraf\BinaryUtilities\Exception\EndianTypeDoesNotExistsException;
use PBurggraf\BinaryUtilities\Exception\EndOfFileReachedException;
use PBurggraf\BinaryUtilities\Exception\FileDoesNotExistsException;
use PBurggraf\BinaryUtilities\Exception\InvalidDataTypeException;

/**
 * @author <NAME> <<EMAIL>>
 */
class BinaryUtilities
{
    const MODE_READ = 'read';
    const MODE_WRITE = 'write';

    const BASE_BINARY = 2;
    const BASE_OCTAL = 7;
    const BASE_DECIMAL = 10;
    const BASE_HEXADECIMAL = 16;

    /**
     * @var string
     */
    protected $file;

    /**
     * @var int
     */
    protected $currentMode;

    /**
     * @var string
     */
    protected $content;

    /**
     * @var int
     */
    protected $endOfFile;

    /**
     * @var int
     */
    protected $base = self::BASE_DECIMAL;

    /**
     * @var array
     */
    protected $buffer = [];

    /**
     * @var int
     */
    protected $currentBit;

    /**
     * @var int
     */
    protected $offset = 0;

    /**
     * @var string
     */
    protected $endian;

    /**
     * @var AbstractDataType[]
     */
    protected $dataTypeClasses = [];

    /**
     * @param string $file
     *
     * @throws FileDoesNotExistsException
     *
     * @return BinaryUtilities
     */
    public function setFile(string $file): BinaryUtilities
    {
        if (!file_exists($file)) {
            throw new FileDoesNotExistsException();
        }
        $this->file = $file;
        $this->setContent();

        return $this;
    }

    /**
     * @param string $mode
     *
     * @return BinaryUtilities
     */
    public function setEndian(string $mode): BinaryUtilities
    {
        $this->endian = $mode;

        return $this;
    }

    /**
     * @param int $offset
     *
     * @throws EndOfFileReachedException
     *
     * @return BinaryUtilities
     */
    public function offset(int $offset): BinaryUtilities
    {
        $this->offset = $offset;

        return $this;
    }

    /**
     * @param int $base
     *
     * @return BinaryUtilities
     */
    public function setBase(int $base = self::BASE_DECIMAL): BinaryUtilities
    {
        $this->base = $base;

        return $this;
    }

    /**
     * @param bool $clearBuffer
     *
     * @return array
     */
    public function returnBuffer(bool $clearBuffer = true): array
    {
        $buffer = $this->buffer;

        if ($clearBuffer) {
            $this->buffer = [];
        }

        return array_map([$this, 'convertToBase'], $buffer);
    }
{'fraction_non_alphanumeric': 0.12021371326803205, 'fraction_numerical': 0.0028495102404274266, 'mean_word_length': 2.192723138146674, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, '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': '6882179', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1736, 'n_words': 341}