API Reference¶
-
compfile.
auto_engine
(path)[source]¶ Automatically determine engine type from file properties and file mode using the registered determining functions
Parameters: path (path-like) – Path to the compressed file Returns: - a subclass of CompFile if successfully find one
- engine, otherwise None
Return type: type, NoneType
-
compfile.
is_compressed_file
(path)[source]¶ Infer if the file is a compressed file from file name (path-like)
Parameters: path (path-like) – Path to the file. Returns: Whether the file is a compressed file. Return type: bool Example
>>> is_compressed_file('a.txt.bz2') True >>> is_compressed_file('a.txt.gz') True >>> is_compressed_file('a.txt') False
-
compfile.
open
(fpath, mode, *args, **kwargs)[source]¶ Open a compressed file as an uncompressed file stream
Parameters: Returns: An uncompressed file stream
Return type: file-object
-
compfile.
register_auto_engine
(func, priority=50, prepend=False)[source]¶ Register automatic engine determing function
Two possible signatures:
register_auto_engine(func, priority=50, prepend=False)
register_auto-engine(priority=50, prepend=False)
The first one can be used as a regular function as well as a decorator. The second one is a decorator with arguments
Parameters: - func (callable) – A callable which determines archive engine from file properties and open mode. The signature should be: func(path, mode) where path is a file-like or path-like object, and mode str to open the file.
- priority (int, float) – Priority of the func, small number means higher priority. When multiple functions are registered by multiple call of register_auto_engine, functions will be used in an ordering determined by thier priortities. Default to 50.
- prepend (bool) – If there is already a function with the same priority registered, insert to the left (before) or right (after) of it. Default to False.
Returns: The first version of signature will return the input callable
func
, therefore it can be used as a decorator (without arguments). The second version will return a decorator wrap.