Skip to content

Commit

Permalink
Accept PathLike objects (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keou0007 authored Oct 9, 2023
1 parent a3f237c commit 3611019
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions xtarfile/xtarfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from itertools import chain
from os import PathLike, fspath
from tarfile import open as tarfile_open
from typing import Union

from xtarfile.zstd import ZstandardTarfile
from xtarfile.lz4 import Lz4Tarfile
Expand All @@ -20,7 +22,8 @@
SUPPORTED_FORMATS = frozenset(chain(_HANDLERS.keys(), _NATIVE_FORMATS))


def get_compression(path: str, mode: str) -> str:
def get_compression(path: Union[str, PathLike], mode: str) -> str:
path = fspath(path)
for delim in (':', '|'):
delim_index = mode.rfind(delim)
if delim_index > -1:
Expand All @@ -33,7 +36,7 @@ def get_compression(path: str, mode: str) -> str:
return ''


def xtarfile_open(path: str, mode: str, **kwargs):
def xtarfile_open(path: Union[str, PathLike], mode: str, **kwargs):
compression = get_compression(path, mode)

if not compression or compression in _NATIVE_FORMATS:
Expand Down

0 comments on commit 3611019

Please sign in to comment.