@@ -70,19 +70,21 @@ def dir2zip(in_dir: str, zip_fname: str, date_time: Optional[datetime] = None) -
7070 st = os .stat (in_dir )
7171 date_time = datetime .fromtimestamp (st .st_mtime , tz = timezone .utc )
7272 date_time_args = date_time .timetuple ()[:6 ]
73- with zipfile .ZipFile (zip_fname , "w" , compression = zipfile .ZIP_DEFLATED ) as z :
73+ compression = zipfile .ZIP_DEFLATED
74+ with zipfile .ZipFile (zip_fname , "w" , compression = compression ) as z :
7475 for root , dirs , files in os .walk (in_dir ):
7576 for dir in dirs :
7677 dname = os .path .join (root , dir )
7778 out_dname = os .path .relpath (dname , in_dir ) + "/"
78- zinfo = zipfile .ZipInfo ( out_dname , date_time = date_time_args )
79- zinfo .external_attr = os . stat ( dname ). st_mode << 16
80- z .writestr (zinfo , "" )
79+ zinfo = zipfile .ZipInfo . from_file ( dname , out_dname )
80+ zinfo .date_time = date_time_args
81+ z .writestr (zinfo , b "" )
8182 for file in files :
8283 fname = os .path .join (root , file )
8384 out_fname = os .path .relpath (fname , in_dir )
84- zinfo = zipfile .ZipInfo (out_fname , date_time = date_time_args )
85- zinfo .external_attr = os .stat (fname ).st_mode << 16
85+ zinfo = zipfile .ZipInfo .from_file (fname , out_fname )
86+ zinfo .date_time = date_time_args
87+ zinfo .compress_type = compression
8688 with open (fname , "rb" ) as fp :
8789 z .writestr (zinfo , fp .read ())
8890
0 commit comments