core.files.uncompress
- core.files.uncompress.get_compression_ext(f: str | Path)[source]
Detect the compression format of a file using the system ‘file’ command.
This function uses the Unix ‘file’ command to determine the compression format of a file based on its content (magic numbers), not just its extension.
Parameters:
- fstr or Path
Path to the file to analyze
Returns:
- str or None
The detected compression extension (‘.zip’, ‘.tar’, ‘.tar.gz’, ‘.tgz’, ‘.gz’, ‘.bz2’, ‘.Z’) or None if no compression is detected
- core.files.uncompress.uncompress(filename, dirname, create_out_dir=True, extract_to_subdir=True, verbose=False) Path[source]
Uncompress filename to dirname
Arguments:
- create_out_dir: bool
create output directory if it does not exist
- extract_to_subdir: bool
if True (default), extract to a subdirectory named after the archive if False, extract directly to dirname
Returns the path to the uncompressed file
- core.files.uncompress.uncompress_decorator(target_name_func=None, verbose=True)[source]
A decorator that uncompresses the result of function f
The file returned by f is uncompressed to dirname
Parameters:
- target_name_funccallable, optional
A function that takes an identifier and returns the target name/path for the uncompressed file. The identifier can be a URL or any string. If None, defaults to using Path(identifier).stem.
- verbosebool
Whether to display verbose output during uncompression
- core.files.uncompress.uncompress_single(filename, output_path, verbose=False)[source]
Decompress a single compressed file (not an archive).
Parameters:
- filenamePath
Path to the compressed file
- output_pathPath
Path where the decompressed file should be written
- verbosebool
Whether to display verbose output
Returns:
- Path
Path to the decompressed file