Skip to content

Commit b2b2a80

Browse files
authored
Pass file mode to compress function (#1384)
1 parent c3a5c7a commit b2b2a80

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

can/io/logger.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __new__( # type: ignore
8888

8989
file_or_filename: AcceptedIOType = filename
9090
if suffix == ".gz":
91-
suffix, file_or_filename = Logger.compress(filename)
91+
suffix, file_or_filename = Logger.compress(filename, *args, **kwargs)
9292

9393
try:
9494
return Logger.message_writers[suffix](file_or_filename, *args, **kwargs)
@@ -98,13 +98,18 @@ def __new__( # type: ignore
9898
) from None
9999

100100
@staticmethod
101-
def compress(filename: StringPathLike) -> Tuple[str, FileLike]:
101+
def compress(
102+
filename: StringPathLike, *args: Any, **kwargs: Any
103+
) -> Tuple[str, FileLike]:
102104
"""
103105
Return the suffix and io object of the decompressed file.
104106
File will automatically recompress upon close.
105107
"""
106108
real_suffix = pathlib.Path(filename).suffixes[-2].lower()
107-
mode = "ab" if real_suffix == ".blf" else "at"
109+
if kwargs.get("append", False):
110+
mode = "ab" if real_suffix == ".blf" else "at"
111+
else:
112+
mode = "wb" if real_suffix == ".blf" else "wt"
108113

109114
return real_suffix, gzip.open(filename, mode)
110115

0 commit comments

Comments
 (0)