files.uncompress
files.uncompress
Functions
| Name | Description |
|---|---|
| get_compression_ext | Detect the compression format of a file using the system ‘file’ command. |
| uncompress | Uncompress filename to dirname |
| uncompress_decorator | A decorator that uncompresses the result of function f |
| uncompress_single | Decompress a single compressed file (not an archive). |
get_compression_ext
files.uncompress.get_compression_ext(f)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:
f : str 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
uncompress
files.uncompress.uncompress(
filename,
target_dir,
create_out_dir=True,
extract_to='auto',
verbose=False,
)Uncompress filename to dirname
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| filename | str or Path | Path to the file to uncompress | required |
| target_dir | str or Path | Directory to uncompress the file to | required |
| create_out_dir | bool | If True, create the output directory if it does not exist. Default is True. | True |
| extract_to | (auto, subdir, target_dir) | ‘auto’: if the root of the archive contains a single file or directory, uncompress it to target_dir. Otherwise uncompress it to archivefolder is a directory named after filename but without the extension. ‘subdir’: Uncompress the content of the archive to archivefolder is a directory named after filename but without the extension. ‘target_dir’: uncompress the content of the archive to |
'auto' |
| verbose | bool | If True, print verbose output. Default is False. | False |
Returns
| Name | Type | Description |
|---|---|---|
| Path | Path to the uncompressed file or directory |
uncompress_decorator
files.uncompress.uncompress_decorator(target_name_func=None, verbose=True)A decorator that uncompresses the result of function f
Signature of f is assumed to be as follows: f(identifier: str, dirname: Path, *args, **kwargs)
The file returned by f is uncompressed to dirname
Parameters:
target_name_func : callable, 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. verbose : bool Whether to display verbose output during uncompression
uncompress_single
files.uncompress.uncompress_single(filename, output_path, verbose=False)Decompress a single compressed file (not an archive).
Parameters:
filename : Path Path to the compressed file output_path : Path
Path where the decompressed file should be written verbose : bool Whether to display verbose output
Returns:
Path Path to the decompressed file