@@ -48,11 +48,10 @@ class ZipArchiver(Archiver):
4848 - Writing new files or updating existing ones
4949 - Removing single files or multiple files in batch
5050 - Copying entire archive contents to a new ZIP file
51- - Automatic cleanup of temporary files and partial operations
51+ - Automatic cleanup of partial operations
5252
5353 Attributes:
5454 path (Path): Path to the ZIP archive file
55- _temp_files (list[Path]): List of temporary files created during operations
5655
5756 Examples:
5857 >>> archiver = ZipArchiver(Path("my_archive.zip"))
@@ -69,13 +68,9 @@ def __init__(self, path: Path) -> None:
6968 path: Path to the ZIP archive file. The file doesn't need to exist
7069 yet - it will be created when first written to.
7170
72- Note:
73- The archiver maintains a list of temporary files that will be
74- automatically cleaned up when the object is destroyed.
7571
7672 """
7773 super ().__init__ (path )
78- self ._temp_files : list [Path ] = []
7974
8075 def read_file (self , archive_file : str ) -> bytes :
8176 """Read the contents of a file from the ZIP archive.
@@ -355,39 +350,3 @@ def _cleanup_partial_file(self) -> None:
355350 self .path .unlink ()
356351 except OSError as e :
357352 logger .warning ("Could not remove partial file %s: %s" , self .path , e )
358-
359- def _cleanup_temp_files (self ) -> None :
360- """Clean up any temporary files created during operations.
361-
362- Removes all temporary files tracked in _temp_files and clears the list.
363- This is automatically called when the archiver is destroyed, but can
364- also be called manually for immediate cleanup.
365-
366- Note:
367- - Silently continues if temp files don't exist
368- - Logs warnings for removal failures
369- - Clears the temp files list after cleanup attempt
370-
371- """
372- for temp_file in self ._temp_files :
373- if temp_file .exists ():
374- try :
375- temp_file .unlink ()
376- except OSError as e :
377- logger .warning ("Could not remove temp file %s: %s" , temp_file , e )
378- self ._temp_files .clear ()
379-
380- def __del__ (self ) -> None :
381- """Clean up resources when archiver is destroyed.
382-
383- Ensures all temporary files are cleaned up when the archiver object
384- is garbage collected. This provides a safety net for resource cleanup
385- even if explicit cleanup is not performed.
386-
387- Note:
388- - Automatically called by Python's garbage collector
389- - Provides fail-safe cleanup of temporary resources
390- - Should not be called directly - use _cleanup_temp_files() instead
391-
392- """
393- self ._cleanup_temp_files ()
0 commit comments