@@ -3624,11 +3624,14 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36243624 fcontents = BytesIO ()
36253625 chunk_size = 1024
36263626 fcencoding = "UTF-8"
3627- if ftype in data_types :
3627+ curcompression = "none"
3628+ if not followlink and ftype in data_types :
36283629 with open (fname , "rb" ) as fpc :
36293630 shutil .copyfileobj (fpc , fcontents )
3631+ typechecktest = CheckCompressionType (fcontents , closefp = False )
3632+ fcontents .seek (0 , 0 )
36303633 fcencoding = GetFileEncoding (fcontents , False )
3631- if (not compresswholefile ):
3634+ if (typechecktest is False and not compresswholefile ):
36323635 fcontents .seek (0 , 2 )
36333636 ucfsize = fcontents .tell ()
36343637 fcontents .seek (0 , 0 )
@@ -3649,10 +3652,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36493652 ilcsize .append (cfcontents .tell ())
36503653 cfcontents .close ()
36513654 else :
3652- try :
3653- ilcsize .append (sys .maxint )
3654- except AttributeError :
3655- ilcsize .append (sys .maxsize )
3655+ ilcsize .append (float ("inf" ))
36563656 ilmin = ilmin + 1
36573657 ilcmin = ilcsize .index (min (ilcsize ))
36583658 curcompression = compressionuselist [ilcmin ]
@@ -3669,13 +3669,16 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36693669 fcompression = curcompression
36703670 fcontents .close ()
36713671 fcontents = cfcontents
3672- if ( followlink and (ftype == 1 or ftype == 2 ) ):
3672+ elif followlink and (ftype == 1 or ftype == 2 ):
36733673 if (not os .path .exists (flinkname )):
36743674 return False
36753675 flstatinfo = os .stat (flinkname )
36763676 with open (flinkname , "rb" ) as fpc :
36773677 shutil .copyfileobj (fpc , fcontents )
3678- if (not compresswholefile ):
3678+ typechecktest = CheckCompressionType (fcontents , closefp = False )
3679+ fcontents .seek (0 , 0 )
3680+ fcencoding = GetFileEncoding (fcontents , False )
3681+ if (typechecktest is False and not compresswholefile ):
36793682 fcontents .seek (0 , 2 )
36803683 ucfsize = fcontents .tell ()
36813684 fcontents .seek (0 , 0 )
@@ -3696,10 +3699,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36963699 ilcsize .append (cfcontents .tell ())
36973700 cfcontents .close ()
36983701 else :
3699- try :
3700- ilcsize .append (sys .maxint )
3701- except AttributeError :
3702- ilcsize .append (sys .maxsize )
3702+ ilcsize .append (float ("inf" ))
37033703 ilmin = ilmin + 1
37043704 ilcmin = ilcsize .index (min (ilcsize ))
37053705 curcompression = compressionuselist [ilcmin ]
@@ -5086,11 +5086,14 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", comp
50865086 fcsize = format (int (0 ), 'x' ).lower ()
50875087 fcontents = BytesIO ()
50885088 fcencoding = "UTF-8"
5089- if ftype in data_types :
5089+ curcompression = "none"
5090+ if not followlink and ftype in data_types :
50905091 with open (fname , "rb" ) as fpc :
50915092 shutil .copyfileobj (fpc , fcontents )
5093+ typechecktest = CheckCompressionType (fcontents , closefp = False )
5094+ fcontents .seek (0 , 0 )
50925095 fcencoding = GetFileEncoding (fcontents , False )
5093- if (not compresswholefile ):
5096+ if (typechecktest is False and not compresswholefile ):
50945097 fcontents .seek (0 , 2 )
50955098 ucfsize = fcontents .tell ()
50965099 fcontents .seek (0 , 0 )
@@ -5111,10 +5114,7 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", comp
51115114 ilcsize .append (cfcontents .tell ())
51125115 cfcontents .close ()
51135116 else :
5114- try :
5115- ilcsize .append (sys .maxint )
5116- except AttributeError :
5117- ilcsize .append (sys .maxsize )
5117+ ilcsize .append (float ("inf" ))
51185118 ilmin = ilmin + 1
51195119 ilcmin = ilcsize .index (min (ilcsize ))
51205120 curcompression = compressionuselist [ilcmin ]
@@ -5131,15 +5131,16 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", comp
51315131 fcompression = curcompression
51325132 fcontents .close ()
51335133 fcontents = cfcontents
5134- if (fcompression == "none" ):
5135- fcompression = ""
5136- if (followlink and (ftype == 1 or ftype == 2 )):
5134+ elif followlink and (ftype == 1 or ftype == 2 ):
51375135 if (not os .path .exists (flinkname )):
51385136 return False
51395137 flstatinfo = os .stat (flinkname )
51405138 with open (flinkname , "rb" ) as fpc :
51415139 shutil .copyfileobj (fpc , fcontents )
5142- if (not compresswholefile ):
5140+ typechecktest = CheckCompressionType (fcontents , closefp = False )
5141+ fcontents .seek (0 , 0 )
5142+ fcencoding = GetFileEncoding (fcontents , False )
5143+ if (typechecktest is False and not compresswholefile ):
51435144 fcontents .seek (0 , 2 )
51445145 ucfsize = fcontents .tell ()
51455146 fcontents .seek (0 , 0 )
@@ -5160,10 +5161,7 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", comp
51605161 ilcsize .append (cfcontents .tell ())
51615162 cfcontents .close ()
51625163 else :
5163- try :
5164- ilcsize .append (sys .maxint )
5165- except AttributeError :
5166- ilcsize .append (sys .maxsize )
5164+ ilcsize .append (float ("inf" ))
51675165 ilmin = ilmin + 1
51685166 ilcmin = ilcsize .index (min (ilcsize ))
51695167 curcompression = compressionuselist [ilcmin ]
@@ -5180,6 +5178,8 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", comp
51805178 fcompression = curcompression
51815179 fcontents .close ()
51825180 fcontents = cfcontents
5181+ if (fcompression == "none" ):
5182+ fcompression = ""
51835183 fcontents .seek (0 , 0 )
51845184 ftypehex = format (ftype , 'x' ).lower ()
51855185 tmpoutlist = [ftypehex , fencoding , fcencoding , fname , flinkname , fsize , fatime , fmtime , fctime , fbtime , fmode , fwinattributes , fcompression ,
@@ -5433,11 +5433,14 @@ def PackArchiveFileFromTarFile(infile, outfile, fmttype="auto", compression="aut
54335433 fcsize = format (int (0 ), 'x' ).lower ()
54345434 fcontents = BytesIO ()
54355435 fcencoding = "UTF-8"
5436+ curcompression = "none"
54365437 if ftype in data_types :
54375438 fpc = tarfp .extractfile (member )
54385439 shutil .copyfileobj (fpc , fcontents )
5440+ typechecktest = CheckCompressionType (fcontents , closefp = False )
5441+ fcontents .seek (0 , 0 )
54395442 fcencoding = GetFileEncoding (fcontents , False )
5440- if (not compresswholefile ):
5443+ if (typechecktest is False and not compresswholefile ):
54415444 fcontents .seek (0 , 2 )
54425445 ucfsize = fcontents .tell ()
54435446 fcontents .seek (0 , 0 )
@@ -5458,10 +5461,7 @@ def PackArchiveFileFromTarFile(infile, outfile, fmttype="auto", compression="aut
54585461 ilcsize .append (cfcontents .tell ())
54595462 cfcontents .close ()
54605463 else :
5461- try :
5462- ilcsize .append (sys .maxint )
5463- except AttributeError :
5464- ilcsize .append (sys .maxsize )
5464+ ilcsize .append (float ("inf" ))
54655465 ilmin = ilmin + 1
54665466 ilcmin = ilcsize .index (min (ilcsize ))
54675467 curcompression = compressionuselist [ilcmin ]
@@ -5731,10 +5731,13 @@ def PackArchiveFileFromZipFile(infile, outfile, fmttype="auto", compression="aut
57315731 fgname = ""
57325732 fcontents = BytesIO ()
57335733 fcencoding = "UTF-8"
5734- if (ftype == 0 ):
5734+ curcompression = "none"
5735+ if ftype == 0 :
57355736 fcontents .write (zipfp .read (member .filename ))
5737+ typechecktest = CheckCompressionType (fcontents , closefp = False )
5738+ fcontents .seek (0 , 0 )
57365739 fcencoding = GetFileEncoding (fcontents , False )
5737- if (not compresswholefile ):
5740+ if (typechecktest is False and not compresswholefile ):
57385741 fcontents .seek (0 , 2 )
57395742 ucfsize = fcontents .tell ()
57405743 fcontents .seek (0 , 0 )
@@ -6045,10 +6048,13 @@ def PackArchiveFileFromRarFile(infile, outfile, fmttype="auto", compression="aut
60456048 fgname = ""
60466049 fcontents = BytesIO ()
60476050 fcencoding = "UTF-8"
6048- if (ftype == 0 ):
6051+ curcompression = "none"
6052+ if ftype == 0 :
60496053 fcontents .write (rarfp .read (member .filename ))
6054+ typechecktest = CheckCompressionType (fcontents , closefp = False )
6055+ fcontents .seek (0 , 0 )
60506056 fcencoding = GetFileEncoding (fcontents , False )
6051- if (not compresswholefile ):
6057+ if (typechecktest is False and not compresswholefile ):
60526058 fcontents .seek (0 , 2 )
60536059 ucfsize = fcontents .tell ()
60546060 fcontents .seek (0 , 0 )
@@ -6069,10 +6075,7 @@ def PackArchiveFileFromRarFile(infile, outfile, fmttype="auto", compression="aut
60696075 ilcsize .append (cfcontents .tell ())
60706076 cfcontents .close ()
60716077 else :
6072- try :
6073- ilcsize .append (sys .maxint )
6074- except AttributeError :
6075- ilcsize .append (sys .maxsize )
6078+ ilcsize .append (float ("inf" ))
60766079 ilmin = ilmin + 1
60776080 ilcmin = ilcsize .index (min (ilcsize ))
60786081 curcompression = compressionuselist [ilcmin ]
@@ -6296,12 +6299,15 @@ def PackArchiveFileFromSevenZipFile(infile, outfile, fmttype="auto", compression
62966299 fgname = ""
62976300 fcontents = BytesIO ()
62986301 fcencoding = "UTF-8"
6299- if (ftype == 0 ):
6302+ curcompression = "none"
6303+ if ftype == 0 :
63006304 fcontents .write (file_content [member .filename ].read ())
6305+ typechecktest = CheckCompressionType (fcontents , closefp = False )
6306+ fcontents .seek (0 , 0 )
63016307 fcencoding = GetFileEncoding (fcontents , False )
63026308 fsize = format (fcontents .tell (), 'x' ).lower ()
63036309 file_content [member .filename ].close ()
6304- if (not compresswholefile ):
6310+ if (typechecktest is False and not compresswholefile ):
63056311 fcontents .seek (0 , 2 )
63066312 ucfsize = fcontents .tell ()
63076313 fcontents .seek (0 , 0 )
@@ -6322,10 +6328,7 @@ def PackArchiveFileFromSevenZipFile(infile, outfile, fmttype="auto", compression
63226328 ilcsize .append (cfcontents .tell ())
63236329 cfcontents .close ()
63246330 else :
6325- try :
6326- ilcsize .append (sys .maxint )
6327- except AttributeError :
6328- ilcsize .append (sys .maxsize )
6331+ ilcsize .append (float ("inf" ))
63296332 ilmin = ilmin + 1
63306333 ilcmin = ilcsize .index (min (ilcsize ))
63316334 curcompression = compressionuselist [ilcmin ]
@@ -8166,10 +8169,13 @@ def RePackArchiveFile(infile, outfile, fmttype="auto", compression="auto", compr
81668169 fcontents = listarchivefiles ['ffilelist' ][reallcfi ]['fcontents' ]
81678170 if (not listarchivefiles ['ffilelist' ][reallcfi ]['fcontentasfile' ]):
81688171 fcontents = BytesIO (fcontents )
8172+ typechecktest = CheckCompressionType (fcontents , closefp = False )
8173+ fcontents .seek (0 , 0 )
81698174 fcencoding = GetFileEncoding (fcontents , False )
81708175 fcompression = ""
81718176 fcsize = format (int (0 ), 'x' ).lower ()
8172- if (not compresswholefile ):
8177+ curcompression = "none"
8178+ if typechecktest is False and not compresswholefile :
81738179 fcontents .seek (0 , 2 )
81748180 ucfsize = fcontents .tell ()
81758181 fcontents .seek (0 , 0 )
@@ -8190,10 +8196,7 @@ def RePackArchiveFile(infile, outfile, fmttype="auto", compression="auto", compr
81908196 ilcsize .append (cfcontents .tell ())
81918197 cfcontents .close ()
81928198 else :
8193- try :
8194- ilcsize .append (sys .maxint )
8195- except AttributeError :
8196- ilcsize .append (sys .maxsize )
8199+ ilcsize .append (float ("inf" ))
81978200 ilmin = ilmin + 1
81988201 ilcmin = ilcsize .index (min (ilcsize ))
81998202 curcompression = compressionuselist [ilcmin ]
@@ -8210,7 +8213,7 @@ def RePackArchiveFile(infile, outfile, fmttype="auto", compression="auto", compr
82108213 fcompression = curcompression
82118214 fcontents .close ()
82128215 fcontents = cfcontents
8213- if ( followlink ) :
8216+ if followlink :
82148217 if (listarchivefiles ['ffilelist' ][reallcfi ]['ftype' ] == 1 or listarchivefiles ['ffilelist' ][reallcfi ]['ftype' ] == 2 ):
82158218 getflinkpath = listarchivefiles ['ffilelist' ][reallcfi ]['flinkname' ]
82168219 flinkid = prelistarchivefiles ['filetoid' ][getflinkpath ]
0 commit comments