Skip to content

Commit 309ac08

Browse files
author
Kazuki Suzuki Przyborowski
committed
Update pycatfile.py
1 parent f1c678c commit 309ac08

1 file changed

Lines changed: 54 additions & 51 deletions

File tree

pycatfile.py

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,11 +3636,14 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36363636
fcontents = BytesIO()
36373637
chunk_size = 1024
36383638
fcencoding = "UTF-8"
3639-
if ftype in data_types:
3639+
curcompression = "none"
3640+
if not followlink and ftype in data_types:
36403641
with open(fname, "rb") as fpc:
36413642
shutil.copyfileobj(fpc, fcontents)
3643+
typechecktest = CheckCompressionType(fcontents, closefp=False)
3644+
fcontents.seek(0, 0)
36423645
fcencoding = GetFileEncoding(fcontents, False)
3643-
if(not compresswholefile):
3646+
if(typechecktest is False and not compresswholefile):
36443647
fcontents.seek(0, 2)
36453648
ucfsize = fcontents.tell()
36463649
fcontents.seek(0, 0)
@@ -3661,10 +3664,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36613664
ilcsize.append(cfcontents.tell())
36623665
cfcontents.close()
36633666
else:
3664-
try:
3665-
ilcsize.append(sys.maxint)
3666-
except AttributeError:
3667-
ilcsize.append(sys.maxsize)
3667+
ilcsize.append(float("inf"))
36683668
ilmin = ilmin + 1
36693669
ilcmin = ilcsize.index(min(ilcsize))
36703670
curcompression = compressionuselist[ilcmin]
@@ -3681,13 +3681,16 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
36813681
fcompression = curcompression
36823682
fcontents.close()
36833683
fcontents = cfcontents
3684-
if(followlink and (ftype == 1 or ftype == 2)):
3684+
elif followlink and (ftype == 1 or ftype == 2):
36853685
if(not os.path.exists(flinkname)):
36863686
return False
36873687
flstatinfo = os.stat(flinkname)
36883688
with open(flinkname, "rb") as fpc:
36893689
shutil.copyfileobj(fpc, fcontents)
3690-
if(not compresswholefile):
3690+
typechecktest = CheckCompressionType(fcontents, closefp=False)
3691+
fcontents.seek(0, 0)
3692+
fcencoding = GetFileEncoding(fcontents, False)
3693+
if(typechecktest is False and not compresswholefile):
36913694
fcontents.seek(0, 2)
36923695
ucfsize = fcontents.tell()
36933696
fcontents.seek(0, 0)
@@ -3708,10 +3711,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
37083711
ilcsize.append(cfcontents.tell())
37093712
cfcontents.close()
37103713
else:
3711-
try:
3712-
ilcsize.append(sys.maxint)
3713-
except AttributeError:
3714-
ilcsize.append(sys.maxsize)
3714+
ilcsize.append(float("inf"))
37153715
ilmin = ilmin + 1
37163716
ilcmin = ilcsize.index(min(ilcsize))
37173717
curcompression = compressionuselist[ilcmin]
@@ -5098,11 +5098,14 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
50985098
fcsize = format(int(0), 'x').lower()
50995099
fcontents = BytesIO()
51005100
fcencoding = "UTF-8"
5101-
if ftype in data_types:
5101+
curcompression = "none"
5102+
if not followlink and ftype in data_types:
51025103
with open(fname, "rb") as fpc:
51035104
shutil.copyfileobj(fpc, fcontents)
5105+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5106+
fcontents.seek(0, 0)
51045107
fcencoding = GetFileEncoding(fcontents, False)
5105-
if(not compresswholefile):
5108+
if(typechecktest is False and not compresswholefile):
51065109
fcontents.seek(0, 2)
51075110
ucfsize = fcontents.tell()
51085111
fcontents.seek(0, 0)
@@ -5123,10 +5126,7 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51235126
ilcsize.append(cfcontents.tell())
51245127
cfcontents.close()
51255128
else:
5126-
try:
5127-
ilcsize.append(sys.maxint)
5128-
except AttributeError:
5129-
ilcsize.append(sys.maxsize)
5129+
ilcsize.append(float("inf"))
51305130
ilmin = ilmin + 1
51315131
ilcmin = ilcsize.index(min(ilcsize))
51325132
curcompression = compressionuselist[ilcmin]
@@ -5143,15 +5143,16 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51435143
fcompression = curcompression
51445144
fcontents.close()
51455145
fcontents = cfcontents
5146-
if(fcompression == "none"):
5147-
fcompression = ""
5148-
if(followlink and (ftype == 1 or ftype == 2)):
5146+
elif followlink and (ftype == 1 or ftype == 2):
51495147
if(not os.path.exists(flinkname)):
51505148
return False
51515149
flstatinfo = os.stat(flinkname)
51525150
with open(flinkname, "rb") as fpc:
51535151
shutil.copyfileobj(fpc, fcontents)
5154-
if(not compresswholefile):
5152+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5153+
fcontents.seek(0, 0)
5154+
fcencoding = GetFileEncoding(fcontents, False)
5155+
if(typechecktest is False and not compresswholefile):
51555156
fcontents.seek(0, 2)
51565157
ucfsize = fcontents.tell()
51575158
fcontents.seek(0, 0)
@@ -5172,10 +5173,7 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51725173
ilcsize.append(cfcontents.tell())
51735174
cfcontents.close()
51745175
else:
5175-
try:
5176-
ilcsize.append(sys.maxint)
5177-
except AttributeError:
5178-
ilcsize.append(sys.maxsize)
5176+
ilcsize.append(float("inf"))
51795177
ilmin = ilmin + 1
51805178
ilcmin = ilcsize.index(min(ilcsize))
51815179
curcompression = compressionuselist[ilcmin]
@@ -5192,6 +5190,8 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
51925190
fcompression = curcompression
51935191
fcontents.close()
51945192
fcontents = cfcontents
5193+
if(fcompression == "none"):
5194+
fcompression = ""
51955195
fcontents.seek(0, 0)
51965196
ftypehex = format(ftype, 'x').lower()
51975197
tmpoutlist = [ftypehex, fencoding, fcencoding, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
@@ -5445,11 +5445,14 @@ def PackCatFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
54455445
fcsize = format(int(0), 'x').lower()
54465446
fcontents = BytesIO()
54475447
fcencoding = "UTF-8"
5448+
curcompression = "none"
54485449
if ftype in data_types:
54495450
fpc = tarfp.extractfile(member)
54505451
shutil.copyfileobj(fpc, fcontents)
5452+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5453+
fcontents.seek(0, 0)
54515454
fcencoding = GetFileEncoding(fcontents, False)
5452-
if(not compresswholefile):
5455+
if(typechecktest is False and not compresswholefile):
54535456
fcontents.seek(0, 2)
54545457
ucfsize = fcontents.tell()
54555458
fcontents.seek(0, 0)
@@ -5470,10 +5473,7 @@ def PackCatFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
54705473
ilcsize.append(cfcontents.tell())
54715474
cfcontents.close()
54725475
else:
5473-
try:
5474-
ilcsize.append(sys.maxint)
5475-
except AttributeError:
5476-
ilcsize.append(sys.maxsize)
5476+
ilcsize.append(float("inf"))
54775477
ilmin = ilmin + 1
54785478
ilcmin = ilcsize.index(min(ilcsize))
54795479
curcompression = compressionuselist[ilcmin]
@@ -5743,10 +5743,13 @@ def PackCatFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
57435743
fgname = ""
57445744
fcontents = BytesIO()
57455745
fcencoding = "UTF-8"
5746-
if(ftype == 0):
5746+
curcompression = "none"
5747+
if ftype == 0:
57475748
fcontents.write(zipfp.read(member.filename))
5749+
typechecktest = CheckCompressionType(fcontents, closefp=False)
5750+
fcontents.seek(0, 0)
57485751
fcencoding = GetFileEncoding(fcontents, False)
5749-
if(not compresswholefile):
5752+
if(typechecktest is False and not compresswholefile):
57505753
fcontents.seek(0, 2)
57515754
ucfsize = fcontents.tell()
57525755
fcontents.seek(0, 0)
@@ -6057,10 +6060,13 @@ def PackCatFileFromRarFile(infile, outfile, fmttype="auto", compression="auto",
60576060
fgname = ""
60586061
fcontents = BytesIO()
60596062
fcencoding = "UTF-8"
6060-
if(ftype == 0):
6063+
curcompression = "none"
6064+
if ftype == 0:
60616065
fcontents.write(rarfp.read(member.filename))
6066+
typechecktest = CheckCompressionType(fcontents, closefp=False)
6067+
fcontents.seek(0, 0)
60626068
fcencoding = GetFileEncoding(fcontents, False)
6063-
if(not compresswholefile):
6069+
if(typechecktest is False and not compresswholefile):
60646070
fcontents.seek(0, 2)
60656071
ucfsize = fcontents.tell()
60666072
fcontents.seek(0, 0)
@@ -6081,10 +6087,7 @@ def PackCatFileFromRarFile(infile, outfile, fmttype="auto", compression="auto",
60816087
ilcsize.append(cfcontents.tell())
60826088
cfcontents.close()
60836089
else:
6084-
try:
6085-
ilcsize.append(sys.maxint)
6086-
except AttributeError:
6087-
ilcsize.append(sys.maxsize)
6090+
ilcsize.append(float("inf"))
60886091
ilmin = ilmin + 1
60896092
ilcmin = ilcsize.index(min(ilcsize))
60906093
curcompression = compressionuselist[ilcmin]
@@ -6308,12 +6311,15 @@ def PackCatFileFromSevenZipFile(infile, outfile, fmttype="auto", compression="au
63086311
fgname = ""
63096312
fcontents = BytesIO()
63106313
fcencoding = "UTF-8"
6311-
if(ftype == 0):
6314+
curcompression = "none"
6315+
if ftype == 0:
63126316
fcontents.write(file_content[member.filename].read())
6317+
typechecktest = CheckCompressionType(fcontents, closefp=False)
6318+
fcontents.seek(0, 0)
63136319
fcencoding = GetFileEncoding(fcontents, False)
63146320
fsize = format(fcontents.tell(), 'x').lower()
63156321
file_content[member.filename].close()
6316-
if(not compresswholefile):
6322+
if(typechecktest is False and not compresswholefile):
63176323
fcontents.seek(0, 2)
63186324
ucfsize = fcontents.tell()
63196325
fcontents.seek(0, 0)
@@ -6334,10 +6340,7 @@ def PackCatFileFromSevenZipFile(infile, outfile, fmttype="auto", compression="au
63346340
ilcsize.append(cfcontents.tell())
63356341
cfcontents.close()
63366342
else:
6337-
try:
6338-
ilcsize.append(sys.maxint)
6339-
except AttributeError:
6340-
ilcsize.append(sys.maxsize)
6343+
ilcsize.append(float("inf"))
63416344
ilmin = ilmin + 1
63426345
ilcmin = ilcsize.index(min(ilcsize))
63436346
curcompression = compressionuselist[ilcmin]
@@ -8178,10 +8181,13 @@ def RePackCatFile(infile, outfile, fmttype="auto", compression="auto", compressw
81788181
fcontents = listarchivefiles['ffilelist'][reallcfi]['fcontents']
81798182
if(not listarchivefiles['ffilelist'][reallcfi]['fcontentasfile']):
81808183
fcontents = BytesIO(fcontents)
8184+
typechecktest = CheckCompressionType(fcontents, closefp=False)
8185+
fcontents.seek(0, 0)
81818186
fcencoding = GetFileEncoding(fcontents, False)
81828187
fcompression = ""
81838188
fcsize = format(int(0), 'x').lower()
8184-
if(not compresswholefile):
8189+
curcompression = "none"
8190+
if typechecktest is False and not compresswholefile:
81858191
fcontents.seek(0, 2)
81868192
ucfsize = fcontents.tell()
81878193
fcontents.seek(0, 0)
@@ -8202,10 +8208,7 @@ def RePackCatFile(infile, outfile, fmttype="auto", compression="auto", compressw
82028208
ilcsize.append(cfcontents.tell())
82038209
cfcontents.close()
82048210
else:
8205-
try:
8206-
ilcsize.append(sys.maxint)
8207-
except AttributeError:
8208-
ilcsize.append(sys.maxsize)
8211+
ilcsize.append(float("inf"))
82098212
ilmin = ilmin + 1
82108213
ilcmin = ilcsize.index(min(ilcsize))
82118214
curcompression = compressionuselist[ilcmin]
@@ -8222,7 +8225,7 @@ def RePackCatFile(infile, outfile, fmttype="auto", compression="auto", compressw
82228225
fcompression = curcompression
82238226
fcontents.close()
82248227
fcontents = cfcontents
8225-
if(followlink):
8228+
if followlink:
82268229
if(listarchivefiles['ffilelist'][reallcfi]['ftype'] == 1 or listarchivefiles['ffilelist'][reallcfi]['ftype'] == 2):
82278230
getflinkpath = listarchivefiles['ffilelist'][reallcfi]['flinkname']
82288231
flinkid = prelistarchivefiles['filetoid'][getflinkpath]

0 commit comments

Comments
 (0)