Skip to content

Commit 3b5c39d

Browse files
author
Kazuki Suzuki Przyborowski
committed
Update pyfoxfile.py
1 parent 7fdd07b commit 3b5c39d

1 file changed

Lines changed: 59 additions & 56 deletions

File tree

pyfoxfile.py

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,11 +3634,14 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36343634
fcontents = BytesIO()
36353635
chunk_size = 1024
36363636
fcencoding = "UTF-8"
3637-
if ftype in data_types:
3637+
curcompression = "none"
3638+
if not followlink and ftype in data_types:
36383639
with open(fname, "rb") as fpc:
36393640
shutil.copyfileobj(fpc, fcontents)
3641+
typechecktest = CheckCompressionType(fcontents, closefp=False)
3642+
fcontents.seek(0, 0)
36403643
fcencoding = GetFileEncoding(fcontents, False)
3641-
if(not compresswholefile):
3644+
if(typechecktest is False and not compresswholefile):
36423645
fcontents.seek(0, 2)
36433646
ucfsize = fcontents.tell()
36443647
fcontents.seek(0, 0)
@@ -3659,10 +3662,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36593662
ilcsize.append(cfcontents.tell())
36603663
cfcontents.close()
36613664
else:
3662-
try:
3663-
ilcsize.append(sys.maxint)
3664-
except AttributeError:
3665-
ilcsize.append(sys.maxsize)
3665+
ilcsize.append(float("inf"))
36663666
ilmin = ilmin + 1
36673667
ilcmin = ilcsize.index(min(ilcsize))
36683668
curcompression = compressionuselist[ilcmin]
@@ -3679,13 +3679,16 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36793679
fcompression = curcompression
36803680
fcontents.close()
36813681
fcontents = cfcontents
3682-
if(followlink and (ftype == 1 or ftype == 2)):
3682+
elif followlink and (ftype == 1 or ftype == 2):
36833683
if(not os.path.exists(flinkname)):
36843684
return False
36853685
flstatinfo = os.stat(flinkname)
36863686
with open(flinkname, "rb") as fpc:
36873687
shutil.copyfileobj(fpc, fcontents)
3688-
if(not compresswholefile):
3688+
typechecktest = CheckCompressionType(fcontents, closefp=False)
3689+
fcontents.seek(0, 0)
3690+
fcencoding = GetFileEncoding(fcontents, False)
3691+
if(typechecktest is False and not compresswholefile):
36893692
fcontents.seek(0, 2)
36903693
ucfsize = fcontents.tell()
36913694
fcontents.seek(0, 0)
@@ -3706,10 +3709,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
37063709
ilcsize.append(cfcontents.tell())
37073710
cfcontents.close()
37083711
else:
3709-
try:
3710-
ilcsize.append(sys.maxint)
3711-
except AttributeError:
3712-
ilcsize.append(sys.maxsize)
3712+
ilcsize.append(float("inf"))
37133713
ilmin = ilmin + 1
37143714
ilcmin = ilcsize.index(min(ilcsize))
37153715
curcompression = compressionuselist[ilcmin]
@@ -5096,11 +5096,14 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
50965096
fcsize = format(int(0), 'x').lower()
50975097
fcontents = BytesIO()
50985098
fcencoding = "UTF-8"
5099-
if ftype in data_types:
5099+
curcompression = "none"
5100+
if not followlink and ftype in data_types:
51005101
with open(fname, "rb") as fpc:
51015102
shutil.copyfileobj(fpc, fcontents)
5103+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5104+
fcontents.seek(0, 0)
51025105
fcencoding = GetFileEncoding(fcontents, False)
5103-
if(not compresswholefile):
5106+
if(typechecktest is False and not compresswholefile):
51045107
fcontents.seek(0, 2)
51055108
ucfsize = fcontents.tell()
51065109
fcontents.seek(0, 0)
@@ -5121,10 +5124,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51215124
ilcsize.append(cfcontents.tell())
51225125
cfcontents.close()
51235126
else:
5124-
try:
5125-
ilcsize.append(sys.maxint)
5126-
except AttributeError:
5127-
ilcsize.append(sys.maxsize)
5127+
ilcsize.append(float("inf"))
51285128
ilmin = ilmin + 1
51295129
ilcmin = ilcsize.index(min(ilcsize))
51305130
curcompression = compressionuselist[ilcmin]
@@ -5141,15 +5141,16 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51415141
fcompression = curcompression
51425142
fcontents.close()
51435143
fcontents = cfcontents
5144-
if(fcompression == "none"):
5145-
fcompression = ""
5146-
if(followlink and (ftype == 1 or ftype == 2)):
5144+
elif followlink and (ftype == 1 or ftype == 2):
51475145
if(not os.path.exists(flinkname)):
51485146
return False
51495147
flstatinfo = os.stat(flinkname)
51505148
with open(flinkname, "rb") as fpc:
51515149
shutil.copyfileobj(fpc, fcontents)
5152-
if(not compresswholefile):
5150+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5151+
fcontents.seek(0, 0)
5152+
fcencoding = GetFileEncoding(fcontents, False)
5153+
if(typechecktest is False and not compresswholefile):
51535154
fcontents.seek(0, 2)
51545155
ucfsize = fcontents.tell()
51555156
fcontents.seek(0, 0)
@@ -5170,10 +5171,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51705171
ilcsize.append(cfcontents.tell())
51715172
cfcontents.close()
51725173
else:
5173-
try:
5174-
ilcsize.append(sys.maxint)
5175-
except AttributeError:
5176-
ilcsize.append(sys.maxsize)
5174+
ilcsize.append(float("inf"))
51775175
ilmin = ilmin + 1
51785176
ilcmin = ilcsize.index(min(ilcsize))
51795177
curcompression = compressionuselist[ilcmin]
@@ -5190,6 +5188,8 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51905188
fcompression = curcompression
51915189
fcontents.close()
51925190
fcontents = cfcontents
5191+
if(fcompression == "none"):
5192+
fcompression = ""
51935193
fcontents.seek(0, 0)
51945194
ftypehex = format(ftype, 'x').lower()
51955195
tmpoutlist = [ftypehex, fencoding, fcencoding, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
@@ -5443,11 +5443,14 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
54435443
fcsize = format(int(0), 'x').lower()
54445444
fcontents = BytesIO()
54455445
fcencoding = "UTF-8"
5446+
curcompression = "none"
54465447
if ftype in data_types:
54475448
fpc = tarfp.extractfile(member)
54485449
shutil.copyfileobj(fpc, fcontents)
5450+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5451+
fcontents.seek(0, 0)
54495452
fcencoding = GetFileEncoding(fcontents, False)
5450-
if(not compresswholefile):
5453+
if(typechecktest is False and not compresswholefile):
54515454
fcontents.seek(0, 2)
54525455
ucfsize = fcontents.tell()
54535456
fcontents.seek(0, 0)
@@ -5468,10 +5471,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
54685471
ilcsize.append(cfcontents.tell())
54695472
cfcontents.close()
54705473
else:
5471-
try:
5472-
ilcsize.append(sys.maxint)
5473-
except AttributeError:
5474-
ilcsize.append(sys.maxsize)
5474+
ilcsize.append(float("inf"))
54755475
ilmin = ilmin + 1
54765476
ilcmin = ilcsize.index(min(ilcsize))
54775477
curcompression = compressionuselist[ilcmin]
@@ -5741,10 +5741,13 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
57415741
fgname = ""
57425742
fcontents = BytesIO()
57435743
fcencoding = "UTF-8"
5744-
if(ftype == 0):
5744+
curcompression = "none"
5745+
if ftype == 0:
57455746
fcontents.write(zipfp.read(member.filename))
5747+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5748+
fcontents.seek(0, 0)
57465749
fcencoding = GetFileEncoding(fcontents, False)
5747-
if(not compresswholefile):
5750+
if(typechecktest is False and not compresswholefile):
57485751
fcontents.seek(0, 2)
57495752
ucfsize = fcontents.tell()
57505753
fcontents.seek(0, 0)
@@ -6055,10 +6058,13 @@ def PackFoxFileFromRarFile(infile, outfile, fmttype="auto", compression="auto",
60556058
fgname = ""
60566059
fcontents = BytesIO()
60576060
fcencoding = "UTF-8"
6058-
if(ftype == 0):
6061+
curcompression = "none"
6062+
if ftype == 0:
60596063
fcontents.write(rarfp.read(member.filename))
6064+
typechecktest = CheckCompressionType(fcontents, closefp=False)
6065+
fcontents.seek(0, 0)
60606066
fcencoding = GetFileEncoding(fcontents, False)
6061-
if(not compresswholefile):
6067+
if(typechecktest is False and not compresswholefile):
60626068
fcontents.seek(0, 2)
60636069
ucfsize = fcontents.tell()
60646070
fcontents.seek(0, 0)
@@ -6079,10 +6085,7 @@ def PackFoxFileFromRarFile(infile, outfile, fmttype="auto", compression="auto",
60796085
ilcsize.append(cfcontents.tell())
60806086
cfcontents.close()
60816087
else:
6082-
try:
6083-
ilcsize.append(sys.maxint)
6084-
except AttributeError:
6085-
ilcsize.append(sys.maxsize)
6088+
ilcsize.append(float("inf"))
60866089
ilmin = ilmin + 1
60876090
ilcmin = ilcsize.index(min(ilcsize))
60886091
curcompression = compressionuselist[ilcmin]
@@ -6306,12 +6309,15 @@ def PackFoxFileFromSevenZipFile(infile, outfile, fmttype="auto", compression="au
63066309
fgname = ""
63076310
fcontents = BytesIO()
63086311
fcencoding = "UTF-8"
6309-
if(ftype == 0):
6312+
curcompression = "none"
6313+
if ftype == 0:
63106314
fcontents.write(file_content[member.filename].read())
6315+
typechecktest = CheckCompressionType(fcontents, closefp=False)
6316+
fcontents.seek(0, 0)
63116317
fcencoding = GetFileEncoding(fcontents, False)
63126318
fsize = format(fcontents.tell(), 'x').lower()
63136319
file_content[member.filename].close()
6314-
if(not compresswholefile):
6320+
if(typechecktest is False and not compresswholefile):
63156321
fcontents.seek(0, 2)
63166322
ucfsize = fcontents.tell()
63176323
fcontents.seek(0, 0)
@@ -6332,10 +6338,7 @@ def PackFoxFileFromSevenZipFile(infile, outfile, fmttype="auto", compression="au
63326338
ilcsize.append(cfcontents.tell())
63336339
cfcontents.close()
63346340
else:
6335-
try:
6336-
ilcsize.append(sys.maxint)
6337-
except AttributeError:
6338-
ilcsize.append(sys.maxsize)
6341+
ilcsize.append(float("inf"))
63396342
ilmin = ilmin + 1
63406343
ilcmin = ilcsize.index(min(ilcsize))
63416344
curcompression = compressionuselist[ilcmin]
@@ -8176,10 +8179,13 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
81768179
fcontents = listfoxfiles['ffilelist'][reallcfi]['fcontents']
81778180
if(not listfoxfiles['ffilelist'][reallcfi]['fcontentasfile']):
81788181
fcontents = BytesIO(fcontents)
8182+
typechecktest = CheckCompressionType(fcontents, closefp=False)
8183+
fcontents.seek(0, 0)
81798184
fcencoding = GetFileEncoding(fcontents, False)
81808185
fcompression = ""
81818186
fcsize = format(int(0), 'x').lower()
8182-
if(not compresswholefile):
8187+
curcompression = "none"
8188+
if typechecktest is False and not compresswholefile:
81838189
fcontents.seek(0, 2)
81848190
ucfsize = fcontents.tell()
81858191
fcontents.seek(0, 0)
@@ -8200,10 +8206,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
82008206
ilcsize.append(cfcontents.tell())
82018207
cfcontents.close()
82028208
else:
8203-
try:
8204-
ilcsize.append(sys.maxint)
8205-
except AttributeError:
8206-
ilcsize.append(sys.maxsize)
8209+
ilcsize.append(float("inf"))
82078210
ilmin = ilmin + 1
82088211
ilcmin = ilcsize.index(min(ilcsize))
82098212
curcompression = compressionuselist[ilcmin]
@@ -8220,11 +8223,11 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
82208223
fcompression = curcompression
82218224
fcontents.close()
82228225
fcontents = cfcontents
8223-
if(followlink):
8224-
if(listfoxfiles['ffilelist'][reallcfi]['ftype'] == 1 or listfoxfiles['ffilelist'][reallcfi]['ftype'] == 2):
8225-
getflinkpath = listfoxfiles['ffilelist'][reallcfi]['flinkname']
8226-
flinkid = prelistfoxfiles['filetoid'][getflinkpath]
8227-
flinkinfo = listfoxfiles['ffilelist'][flinkid]
8226+
if followlink:
8227+
if(listarchivefiles['ffilelist'][reallcfi]['ftype'] == 1 or listarchivefiles['ffilelist'][reallcfi]['ftype'] == 2):
8228+
getflinkpath = listarchivefiles['ffilelist'][reallcfi]['flinkname']
8229+
flinkid = prelistarchivefiles['filetoid'][getflinkpath]
8230+
flinkinfo = listarchivefiles['ffilelist'][flinkid]
82288231
fheadersize = format(
82298232
int(flinkinfo['fheadersize']), 'x').lower()
82308233
fsize = format(int(flinkinfo['fsize']), 'x').lower()
@@ -8261,7 +8264,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
82618264
ftypehex = format(flinkinfo['ftype'], 'x').lower()
82628265
else:
82638266
ftypehex = format(
8264-
listfoxfiles['ffilelist'][reallcfi]['ftype'], 'x').lower()
8267+
listarchivefiles['ffilelist'][reallcfi]['ftype'], 'x').lower()
82658268
fcurfid = format(curfid, 'x').lower()
82668269
if(not followlink and finode != 0):
82678270
if(listfoxfiles['ffilelist'][reallcfi]['ftype'] != 1):

0 commit comments

Comments
 (0)