<commit_before># -*- coding: utf-8 -*-

"""Binary data provider."""

from pathlib import Path
from typing import Any, Union

from mimesis.enums import (
    AudioFile,
    CompressedFile,
    DocumentFile,
    ImageFile,
    VideoFile,
)
from mimesis.providers.base import BaseProvider

__all__ = ["BinaryFile"]


class BinaryFile(BaseProvider):
    """Class for generating binary data"""

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        """Initialize attributes.

        :param locale: Current locale.
        :param seed: Seed.
        """
        super().__init__(*args, **kwargs)
        self._data_dir = Path(__file__).parent.parent

    class Meta:
        """Class for metadata."""

        name = "binaryfile"

    def _read_file(
        self,
        *,
        file_type: Union[
            AudioFile,
            CompressedFile,
            DocumentFile,
            ImageFile,
            VideoFile,
        ],
    ) -> bytes:
        file_type = self.validate_enum(file_type, file_type.__class__)
        file_path = self._data_dir.joinpath("data", "bin", f"sample.{file_type}")

        with open(file_path, "rb") as file:
            return file.read()<commit_msg>Fix BinaryFile<commit_after># -*- coding: utf-8 -*-

"""Binary data provider."""

from pathlib import Path
from typing import Any, Union

from mimesis.enums import (
    AudioFile,
    CompressedFile,
    DocumentFile,
    ImageFile,
    VideoFile,
)
from mimesis.providers.base import BaseProvider

__all__ = ["BinaryFile"]


class BinaryFile(BaseProvider):
    """Class for generating binary data"""

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        """Initialize attributes.

        :param locale: Current locale.
        :param seed: Seed.
        """
        super().__init__(*args, **kwargs)
        self._data_dir = Path(__file__).parent.parent
        self._sample_name = 'sample'

    class Meta:
        """Class for metadata."""

        name = "binaryfile"

    def _read_file(
        self,
        *,
        file_type: Union[
            AudioFile,
            CompressedFile,
            DocumentFile,
            ImageFile,
            VideoFile,
        ],
    ) -> bytes:
        file_type = self.validate_enum(file_type, file_type.__class__)
        file_path = self._data_dir.joinpath("data", "bin", f"{self._sample_name}.{file_type}")

        with open(file_path, "rb") as file:
            return file.read()
{'fraction_non_alphanumeric': 0.11954304365565076, 'fraction_numerical': 0.0008159934720522236, 'mean_word_length': 2.239101717305152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '795189', 'n_tokens_mistral': 726, 'n_tokens_neox': 710, 'n_words': 178}