@@ -77,8 +77,8 @@ def add_files(self, *paths, **kw):
7777
7878 def add_file_from_memory (
7979 self , entry_path , entry_size , entry_data ,
80- filetype = REGULAR_FILE ,
81- permission = DEFAULT_UNIX_PERMISSION
80+ filetype = REGULAR_FILE , permission = DEFAULT_UNIX_PERMISSION ,
81+ atime = None , mtime = None , ctime = None , birthtime = None ,
8282 ):
8383 """"Add file from memory to archive.
8484
@@ -93,6 +93,14 @@ def add_file_from_memory(
9393 :type filetype: octal number
9494 :param permission: with which permission should entry be created
9595 :type permission: octal number
96+ :param atime: Last access time
97+ :type atime: int seconds or tuple (int seconds, int nanoseconds)
98+ :param mtime: Last modified time
99+ :type mtime: int seconds or tuple (int seconds, int nanoseconds)
100+ :param ctime: Creation time
101+ :type ctime: int seconds or tuple (int seconds, int nanoseconds)
102+ :param birthtime: Birth time (for archive formats that support it)
103+ :type birthtime: int seconds or tuple (int seconds, int nanoseconds)
96104 """
97105 archive_pointer = self ._pointer
98106
@@ -110,6 +118,23 @@ def add_file_from_memory(
110118 entry_set_size (archive_entry_pointer , entry_size )
111119 entry_set_filetype (archive_entry_pointer , filetype )
112120 entry_set_perm (archive_entry_pointer , permission )
121+
122+ if atime is not None :
123+ if not isinstance (atime , tuple ):
124+ atime = (atime , 0 )
125+ archive_entry .set_atime (* atime )
126+ if mtime is not None :
127+ if not isinstance (mtime , tuple ):
128+ mtime = (mtime , 0 )
129+ archive_entry .set_mtime (* mtime )
130+ if ctime is not None :
131+ if not isinstance (ctime , tuple ):
132+ ctime = (ctime , 0 )
133+ archive_entry .set_ctime (* ctime )
134+ if birthtime is not None :
135+ if not isinstance (birthtime , tuple ):
136+ birthtime = (birthtime , 0 )
137+ archive_entry .set_birthtime (* birthtime )
113138 write_header (archive_pointer , archive_entry_pointer )
114139
115140 for chunk in entry_data :
0 commit comments