isbinary Package

isbinary Package

isbinary.__init__.get_starting_chunk(filename: Union[str, os.PathLike], /, *, chunk_len: int = 2028) bytes[source]
Parameters
  • filename (Union[str, os.PathLike]) – File to open and get the first little chunk of.

  • chunk_len (int) – Number of bytes to read, default 2048.

Returns

Starting chunk of bytes.

Return type

bytes

class isbinary.__init__.BinaryLikeliness(value)[source]

Bases: enum.Enum

An enumeration.

HIGH = 1
MID = 2
LOW = 3
property likely: bool
isbinary.__init__.is_likely_binary(bytes_to_check: bytes, /) isbinary.check.BinaryLikeliness[source]
Parameters

bytes_to_check (bytes) – A chunk of bytes to check.

Returns

True if is likely binary, False otherwise.

Return type

isbinary.check.BinaryLikeliness

isbinary.__init__.is_decodable_as_unicode(bytes_to_check: bytes, /) bool[source]
Parameters

bytes_to_check (bytes) – A chunk of bytes to check.

Returns

True if is unicode-decodable, False otherwise.

Return type

bool

isbinary.__init__.has_null_bytes(bytes_to_check: bytes, /) bool[source]
Parameters

bytes_to_check (bytes) – A chunk of bytes to check.

Returns

True if the chunk contains null bytes, False otherwise.

Return type

bool

isbinary.__init__.is_binary_string(bytes_to_check: bytes, /) bool[source]

Uses a simplified version of the Perl detection algorithm, based roughly on Eli Bendersky’s translation to Python: https://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/

This is biased slightly more in favour of deeming files as text files than the Perl algorithm, since all ASCII compatible character sets are accepted as text, not just utf-8.

Parameters

bytes_to_check (bytes) – A chunk of bytes to check.

Returns

True if the chunk appears to be binary (not text), False otherwise.

Return type

bool

isbinary.__init__.is_binary_file(filename: Union[str, os.PathLike], /, *, starting_chunk_len: int = 2028) bool[source]
Parameters
  • filename (Union[str, os.PathLike]) – File to check.

  • starting_chunk_len (int) – Number of bytes to read, default 2048.

Returns

True if it’s a binary file, otherwise False.

Return type

bool