mt.base.filetype

Extra subroutines using package ‘filetype’ asynchronously.

Functions

async mt.base.filetype.read_file_header(filepath, context_vars: dict = {})

An asyn function that reads the file header so :module:`filetype` can work on.

Parameters:
  • filepath (str) – path to the file whose first 261 bytes would be read

  • context_vars (dict) – a dictionary of context variables within which the function runs. It must include context_vars[‘async’] to tell whether to invoke the function asynchronously or not.

Returns:

buf – first 261 bytes of the file content or a ValueError is raised if the file is shorter

Return type:

bytes

async mt.base.filetype.is_image_asyn(filepath, context_vars: dict = {})

An asyn function that checks if a file is an image.

Parameters:
  • filepath (str) – path to the file that can be an image file

  • context_vars (dict) – a dictionary of context variables within which the function runs. It must include context_vars[‘async’] to tell whether to invoke the function asynchronously or not.

Returns:

whether or not the file is an image file

Return type:

bool

See also

filetype.is_image()

the wrapped function

async mt.base.filetype.image_match_asyn(filepath, context_vars: dict = {})

An asyn function that obtains the image file type.

Parameters:
  • filepath (str) – path to the file that can be an image file

  • context_vars (dict) – a dictionary of context variables within which the function runs. It must include context_vars[‘async’] to tell whether to invoke the function asynchronously or not.

Returns:

the file type, with mime and extension attributes

Return type:

filetype.Type