Skip to content

Commit

Permalink
More os to Path conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-S-Rosen committed Sep 4, 2023
1 parent a88461c commit b4b0a9c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions monty/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ def decompress_file(filepath: str | Path) -> str | None:
str: The decompressed file path.
"""
filepath = Path(filepath)
toks = str(filepath).split(".")
file_ext = toks[-1].upper()
if file_ext in ["BZ2", "GZ", "Z"] and filepath.is_file():
decompressed_file = ".".join(toks[0:-1])
file_ext = filepath.suffix
if file_ext.lower() in [".bz2", ".gz", ".z"] and filepath.is_file():
decompressed_file = Path(str(filepath).removesuffix(file_ext))
with zopen(filepath, "rb") as f_in, open(decompressed_file, "wb") as f_out:
f_out.writelines(f_in)
os.remove(filepath)
Expand Down

0 comments on commit b4b0a9c

Please sign in to comment.