From bc96cea2b9251612ff937ffac89f524dda8a87d3 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 27 Oct 2025 17:22:08 +0100 Subject: [PATCH] feat: change record file export to use LZMA --- src/record_file.py | 9 +++++---- src/recorder.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/record_file.py b/src/record_file.py index 425e620..ecc1611 100644 --- a/src/record_file.py +++ b/src/record_file.py @@ -1,3 +1,4 @@ +import lzma from pathlib import Path import struct import time @@ -12,7 +13,7 @@ class RecordFile: def __init__(self, path: str | Path, mode: Literal["w", "r"]) -> None: self.path: str | Path = path self.mode: Literal["w", "r"] = mode - self.file = open(self.path, self.mode + "b") + self.file: lzma.LZMAFile = lzma.LZMAFile(self.path, self.mode) def __enter__(self): return self @@ -21,8 +22,7 @@ class RecordFile: self.file.close() def write_header(self, n_snapshots: int): - data: bytes = struct.pack( - ">IId", self.VERSION, n_snapshots, time.time()) + data: bytes = struct.pack(">IId", self.VERSION, n_snapshots, time.time()) self.file.write(data) def write_snapshots(self, snapshots: list[Snapshot]): @@ -35,7 +35,8 @@ class RecordFile: version: int = struct.unpack(">I", self.file.read(4))[0] if version != self.VERSION: raise ValueError( - f"Cannot parse record file with format version {version} (current version: {self.VERSION})") + f"Cannot parse record file with format version {version} (current version: {self.VERSION})" + ) n_snapshots: int timestamp: float diff --git a/src/recorder.py b/src/recorder.py index f2f9b88..49a6187 100644 --- a/src/recorder.py +++ b/src/recorder.py @@ -243,7 +243,7 @@ class RecorderWindow(Ui_Recorder, QMainWindow): self.SAVE_DIR.mkdir(exist_ok=True) - record_name: str = "record_%d.rec" + record_name: str = "record_%d.rec.xz" fid = 0 while os.path.exists(self.SAVE_DIR / (record_name % fid)): fid += 1