TypeFind#
- class TypeFind(*args, **kwargs)#
The following functions allow you to detect the media type of an unknown stream.
Methods#
- class TypeFind
-
- peek(offset: int, size: int) int | None#
Returns the
sizebytes of the stream to identify beginning at offset. If offset is a positive number, the offset is relative to the beginning of the stream, if offset is a negative number the offset is relative to the end of the stream. The returned memory is valid until the typefinding function returns and must not be freed.- Parameters:
offset – The offset
size – The number of bytes to return
- classmethod register(name: str, rank: int, func: Callable[[TypeFind, Any], None], extensions: str | None = None, possible_caps: Caps | None = None, data: Any = None) bool#
Registers a new typefind function to be used for typefinding. After registering this function will be available for typefinding. This function is typically called during an element’s plugin initialization.
- Parameters:
name – The name for registering
rank – The rank (or importance) of this typefind function
func – The
TypeFindFunctionto useextensions – Optional comma-separated list of extensions that could belong to this type
possible_caps – Optionally the caps that could be returned when typefinding succeeds
data – Optional user data. This user data must be available until the plugin is unloaded.
- suggest(probability: int, caps: Caps) None#
If a
TypeFindFunctioncalls this function it suggests the caps with the given probability. ATypeFindFunctionmay supply different suggestions in one call. It is up to the caller of theTypeFindFunctionto interpret these values.- Parameters:
probability – The probability in percent that the suggestion is right
caps – The fixed
Capsto suggest
- suggest_empty_simple(probability: int, media_type: str) None#
If a
TypeFindFunctioncalls this function it suggests caps of the givenmedia_typewith the givenprobability.This function is similar to
suggest_simple(), but uses aCapswith no fields.Added in version 1.20.
- Parameters:
probability – The probability in percent that the suggestion is right
media_type – the media type of the suggested caps
Fields#
- class TypeFind
- data#
The data used by the caller of the typefinding function.