diff --git a/can/io/logger.py b/can/io/logger.py index b50825d3f..67b738218 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -88,7 +88,7 @@ def __new__( # type: ignore file_or_filename: AcceptedIOType = filename if suffix == ".gz": - suffix, file_or_filename = Logger.compress(filename) + suffix, file_or_filename = Logger.compress(filename, *args, **kwargs) try: return Logger.message_writers[suffix](file_or_filename, *args, **kwargs) @@ -98,13 +98,18 @@ def __new__( # type: ignore ) from None @staticmethod - def compress(filename: StringPathLike) -> Tuple[str, FileLike]: + def compress( + filename: StringPathLike, *args: Any, **kwargs: Any + ) -> Tuple[str, FileLike]: """ Return the suffix and io object of the decompressed file. File will automatically recompress upon close. """ real_suffix = pathlib.Path(filename).suffixes[-2].lower() - mode = "ab" if real_suffix == ".blf" else "at" + if kwargs.get("append", False): + mode = "ab" if real_suffix == ".blf" else "at" + else: + mode = "wb" if real_suffix == ".blf" else "wt" return real_suffix, gzip.open(filename, mode)