Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit 405a9b2

Browse files
committed
Fix type ref
1 parent e97f56b commit 405a9b2

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

varc_core/systems/base_system.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@
3636
_MAX_OPEN_FILE_SIZE = 10000000 # 10 Mb max dumped filesize
3737

3838

39+
class _TarLz4Wrapper:
40+
41+
def __init__(self, path) -> None:
42+
self._lz4 = lz4.frame.open(path, 'wb')
43+
self._tar = tarfile.open(fileobj=self._lz4f, mode="w")
44+
45+
def writestr(self, path: str, value: str | bytes):
46+
info = tarfile.TarInfo(path)
47+
info.size = len(value)
48+
self._tar.addfile(info, io.BytesIO(value))
49+
50+
def write(self, path: str, arcname: str):
51+
self._tar.add(path, arcname)
52+
53+
def __enter__(self):
54+
return self
55+
56+
def __exit__(self, type, value, traceback):
57+
self._tar.close()
58+
self._lz4.close()
59+
60+
3961
class BaseSystem:
4062
"""A
4163
@@ -317,7 +339,7 @@ def acquire_volatile(self) -> None:
317339
except FileNotFoundError:
318340
logging.warning(f"Could not open {file_path} for reading")
319341

320-
def _open_output(self) -> zipfile.ZipFile | "_TarLz4Wrapper":
342+
def _open_output(self) -> zipfile.ZipFile | _TarLz4Wrapper:
321343
if self.output_path.endswith('.tar.lz4'):
322344
return _TarLz4Wrapper(self.output_path)
323345
else:
@@ -359,24 +381,3 @@ def yara_hit_callback(hit: dict) -> Any:
359381
else:
360382
logging.info("No YARA rules were triggered. Nothing will be written to the output archive.")
361383

362-
363-
class _TarLz4Wrapper:
364-
365-
def __init__(self, path) -> None:
366-
self._lz4 = lz4.frame.open(path, 'wb')
367-
self._tar = tarfile.open(fileobj=self._lz4f, mode="w")
368-
369-
def writestr(self, path: str, value: str | bytes):
370-
info = tarfile.TarInfo(path)
371-
info.size = len(value)
372-
self._tar.addfile(info, io.BytesIO(value))
373-
374-
def write(self, path: str, arcname: str):
375-
self._tar.add(path, arcname)
376-
377-
def __enter__(self):
378-
return self
379-
380-
def __exit__(self, type, value, traceback):
381-
self._tar.close()
382-
self._lz4.close()

0 commit comments

Comments
 (0)