36
36
_MAX_OPEN_FILE_SIZE = 10000000 # 10 Mb max dumped filesize
37
37
38
38
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
+
39
61
class BaseSystem :
40
62
"""A
41
63
@@ -317,7 +339,7 @@ def acquire_volatile(self) -> None:
317
339
except FileNotFoundError :
318
340
logging .warning (f"Could not open { file_path } for reading" )
319
341
320
- def _open_output (self ) -> zipfile .ZipFile | " _TarLz4Wrapper" :
342
+ def _open_output (self ) -> zipfile .ZipFile | _TarLz4Wrapper :
321
343
if self .output_path .endswith ('.tar.lz4' ):
322
344
return _TarLz4Wrapper (self .output_path )
323
345
else :
@@ -359,24 +381,3 @@ def yara_hit_callback(hit: dict) -> Any:
359
381
else :
360
382
logging .info ("No YARA rules were triggered. Nothing will be written to the output archive." )
361
383
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