|
5 | 5 | - https://bitbucket.org/tobylorenz/vector_asc/src/47556e1a6d32c859224ca62d075e1efcc67fa690/src/Vector/ASC/tests/unittests/data/CAN_Log_Trigger_3_2.asc?at=master&fileviewer=file-view-default
|
6 | 6 | - under `test/data/logfile.asc`
|
7 | 7 | """
|
8 |
| - |
| 8 | +import gzip |
9 | 9 | from typing import cast, Any, Generator, IO, List, Optional, Dict
|
10 | 10 |
|
11 | 11 | from datetime import datetime
|
@@ -396,3 +396,51 @@ def on_message_received(self, msg: Message) -> None:
|
396 | 396 | data=" ".join(data),
|
397 | 397 | )
|
398 | 398 | self.log_event(serialized, msg.timestamp)
|
| 399 | + |
| 400 | + |
| 401 | +class CompressedASCReader(ASCReader): |
| 402 | + """Gzipped version of :class:`~can.ASCReader`""" |
| 403 | + |
| 404 | + def __init__( |
| 405 | + self, |
| 406 | + file: Union[typechecking.FileLike, typechecking.StringPathLike], |
| 407 | + base: str = "hex", |
| 408 | + relative_timestamp: bool = True, |
| 409 | + ): |
| 410 | + """ |
| 411 | + :param file: a path-like object or as file-like object to read from |
| 412 | + If this is a file-like object, is has to opened in text |
| 413 | + read mode, not binary read mode. |
| 414 | + :param base: Select the base(hex or dec) of id and data. |
| 415 | + If the header of the asc file contains base information, |
| 416 | + this value will be overwritten. Default "hex". |
| 417 | + :param relative_timestamp: Select whether the timestamps are |
| 418 | + `relative` (starting at 0.0) or `absolute` (starting at |
| 419 | + the system time). Default `True = relative`. |
| 420 | + """ |
| 421 | + super(CompressedASCReader, self).__init__( |
| 422 | + gzip.open(file, mode="rt"), base, relative_timestamp |
| 423 | + ) |
| 424 | + |
| 425 | + |
| 426 | +class CompressedASCWriter(ASCWriter): |
| 427 | + """Gzipped version of :class:`~can.ASCWriter`""" |
| 428 | + |
| 429 | + def __init__( |
| 430 | + self, |
| 431 | + file: Union[typechecking.FileLike, typechecking.StringPathLike], |
| 432 | + channel: int = 1, |
| 433 | + compresslevel: int = 6, |
| 434 | + ): |
| 435 | + """ |
| 436 | + :param file: a path-like object or as file-like object to write to |
| 437 | + If this is a file-like object, is has to opened in text |
| 438 | + write mode, not binary write mode. |
| 439 | + :param channel: a default channel to use when the message does not |
| 440 | + have a channel set |
| 441 | + :param compresslevel: Gzip compresslevel, see |
| 442 | + :class:`~gzip.GzipFile` for details. The default is 6. |
| 443 | + """ |
| 444 | + super(CompressedASCWriter, self).__init__( |
| 445 | + gzip.open(file, mode="wt", compresslevel=compresslevel), channel |
| 446 | + ) |
0 commit comments