duck.http.mimes¶
Module Contents¶
Functions¶
Determine the MIME type of the provided content or file based on its initial bytes (magic numbers). |
|
Determine the MIME type of a file based on its filename or content. |
API¶
- duck.http.mimes.guess_data_mimetype(data: bytes) str[source]¶
Determine the MIME type of the provided content or file based on its initial bytes (magic numbers).
- Parameters:
data – The input data for which the MIME type needs to be determined.
- Returns:
The determined MIME type of the input data.
- Return type:
str
- duck.http.mimes.guess_file_mimetype(filename: str) str[source]¶
Determine the MIME type of a file based on its filename or content.
This function first attempts to guess the MIME type using the file’s extension by leveraging the
mimetypesmodule. If the MIME type could not be determined from the filename, it reads the file content and attempts to infer the MIME type from the data.- Parameters:
filename – The path to the file for which the MIME type needs to be determined.
- Returns:
The determined MIME type of the file. Defaults to ‘application/octet-stream’ if the type cannot be determined.
- Return type:
str