diff --git a/mario/utils.py b/mario/utils.py index 6d43f6f..4dc529c 100644 --- a/mario/utils.py +++ b/mario/utils.py @@ -1,5 +1,7 @@ import os from datetime import datetime +import logging +logger = logging.getLogger(__name__) def append_current_date_to_file_name(file_name: str) -> str: @@ -29,3 +31,27 @@ def gzip_file(input_path, output_path=None): with open(input_path, "rb") as f_in, gzip.open(output_path, "wb") as f_out: shutil.copyfileobj(f_in, f_out) return output_path + + +def decompress_gzip_file(input_path, output_path=None): + import gzip + import os + import shutil + if not input_path.endswith(".gz"): + raise ValueError(f"Input path must end with '.gz': {input_path}") + + if output_path is None: + output_path = input_path.removesuffix(".gz") + + # Create output directory if not exists + output_dir = os.path.dirname(output_path) + if output_dir: + os.makedirs(output_dir, exist_ok=True) + + if os.path.exists(output_path): + logger.warning(f"Output file already exists and will be overwritten: {output_path}") + + with gzip.open(input_path, "rb") as f_in, open(output_path, "wb") as f_out: + shutil.copyfileobj(f_in, f_out) + + return output_path \ No newline at end of file