@@ -78,7 +78,11 @@ def add_files(self, *paths, **kw):
7878 def add_file_from_memory (
7979 self , entry_path , entry_size , entry_data ,
8080 filetype = REGULAR_FILE ,
81- permission = DEFAULT_UNIX_PERMISSION
81+ permission = DEFAULT_UNIX_PERMISSION ,
82+ atime = None ,
83+ mtime = None ,
84+ ctime = None ,
85+ birthtime = None ,
8286 ):
8387 """"Add file from memory to archive.
8488
@@ -93,6 +97,14 @@ def add_file_from_memory(
9397 :type filetype: octal number
9498 :param permission: with which permission should entry be created
9599 :type permission: octal number
100+ :param atime: Last access time
101+ :type atime: int seconds or tuple (int seconds, int nanoseconds)
102+ :param mtime: Last modified time
103+ :type mtime: int seconds or tuple (int seconds, int nanoseconds)
104+ :param ctime: Creation time
105+ :type ctime: int seconds or tuple (int seconds, int nanoseconds)
106+ :param birthtime: Birth time (for archive formats that support it)
107+ :type birthtime: int seconds or tuple (int seconds, int nanoseconds)
96108 """
97109 archive_pointer = self ._pointer
98110
@@ -110,6 +122,23 @@ def add_file_from_memory(
110122 entry_set_size (archive_entry_pointer , entry_size )
111123 entry_set_filetype (archive_entry_pointer , filetype )
112124 entry_set_perm (archive_entry_pointer , permission )
125+
126+ if atime is not None :
127+ archive_entry .set_atime (* (
128+ (atime , 0 )
129+ if isinstance (atime , (int , float )) else atime ))
130+ if mtime is not None :
131+ archive_entry .set_mtime (* (
132+ (mtime , 0 )
133+ if isinstance (mtime , (int , float )) else mtime ))
134+ if ctime is not None :
135+ archive_entry .set_ctime (* (
136+ (ctime , 0 )
137+ if isinstance (ctime , (int , float )) else ctime ))
138+ if birthtime is not None :
139+ archive_entry .set_birthtime (* (
140+ (birthtime , 0 )
141+ if isinstance (birthtime , (int , float )) else birthtime ))
113142 write_header (archive_pointer , archive_entry_pointer )
114143
115144 for chunk in entry_data :
0 commit comments