feat: change record file export to use LZMA
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user