Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions mario/utils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Loading