Skip to content

Commit 8c7d613

Browse files
Add files via upload
1 parent 0599609 commit 8c7d613

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

pycatfile.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -587,21 +587,9 @@ def _get(section_dict, key, default=None):
587587
__include_defaults__ = True
588588
if(__include_defaults__):
589589
if("CatFile" not in __file_format_multi_dict__):
590-
__file_format_multi_dict__.update( { 'CatFile': {'format_name': "CatFile", 'format_magic': "CatFile", 'format_len': 7, 'format_hex': "43617446696c65", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".cat" } } )
591-
if("NekoFile" not in __file_format_multi_dict__):
592-
__file_format_multi_dict__.update( { 'NekoFile': {'format_name': "NekoFile", 'format_magic': "NekoFile", 'format_len': 8, 'format_hex': "4e656b6f46696c65", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".neko" } } )
593-
if("ねこファイル" not in __file_format_multi_dict__):
594-
__file_format_multi_dict__.update( { 'ねこファイル': {'format_name': "NekoFairu", 'format_magic': "ねこファイル", 'format_len': 18, 'format_hex': "e381ade38193e38395e382a1e382a4e383ab", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".ねこ" } } )
595-
if("ネコファイル" not in __file_format_multi_dict__):
596-
__file_format_multi_dict__.update( { 'ネコファイル': {'format_name': "NekoFairu", 'format_magic': "ネコファイル", 'format_len': 18, 'format_hex': "e381ade38193e38395e382a1e382a4e383ab", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".ネコ" } } )
597-
if("네코파일" not in __file_format_multi_dict__):
598-
__file_format_multi_dict__.update( { '네코파일': {'format_name': "NekoPa-il", 'format_magic': "네코파일", 'format_len': 12, 'format_hex': "eb84a4ecbd94ed8c8cec9dbc", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".네코" } } )
599-
if("고양이파일" not in __file_format_multi_dict__):
600-
__file_format_multi_dict__.update( { '고양이파일': {'format_name': "GoyangiPa-il", 'format_magic': "고양이파일", 'format_len': 15, 'format_hex': "eab3a0ec9691ec9db4ed8c8cec9dbc", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".고양이" } } )
601-
if("内酷法伊鲁" not in __file_format_multi_dict__):
602-
__file_format_multi_dict__.update( { '内酷法伊鲁': {'format_name': "NèiKùFǎYīLǔ", 'format_magic': "内酷法伊鲁", 'format_len': 15, 'format_hex': "e58685e985b7e6b395e4bc8ae9b281", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".内酷" } } )
603-
if("猫文件" not in __file_format_multi_dict__):
604-
__file_format_multi_dict__.update( { '猫文件': {'format_name': "MāoWénjiàn", 'format_magic': "猫文件", 'format_len': 9, 'format_hex': "e78cabe69687e4bbb6", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".猫" } } )
590+
__file_format_multi_dict__.update( { 'CatFile': {'format_name': "CatFile", 'format_magic': "CatFile", 'format_len': 11, 'format_hex': "4172636869766546696c65", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".arc" } } )
591+
if("NeoFile" not in __file_format_multi_dict__):
592+
__file_format_multi_dict__.update( { 'NeoFile': {'format_name': "NeoFile", 'format_magic': "NeoFile", 'format_len': 7, 'format_hex': "4e656f46696c65", 'format_delimiter': "\x00", 'format_ver': "001", 'new_style': True, 'use_advanced_list': True, 'use_alt_inode': False, 'format_extension': ".neo" } } )
605593
if(__file_format_default__ not in __file_format_multi_dict__):
606594
__file_format_default__ = next(iter(__file_format_multi_dict__))
607595
__file_format_name__ = __file_format_multi_dict__[__file_format_default__]['format_name']
@@ -5944,9 +5932,9 @@ def ReadInMultipleFileWithContentToArray(infile, fmttype="auto", filestart=0, se
59445932
pass
59455933
else:
59465934
infile = [infile]
5947-
outretval = {}
5935+
outretval = []
59485936
for curfname in infile:
5949-
outretval[curfname] = ReadInFileWithContentToArray(curfname, fmttype, filestart, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend)
5937+
outretval.append(ReadInFileWithContentToArray(curfname, fmttype, filestart, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend))
59505938
return outretval
59515939

59525940
def ReadInMultipleFilesWithContentToArray(infile, fmttype="auto", filestart=0, seekstart=0, seekend=0, listonly=False, contentasfile=True, uncompress=True, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False):
@@ -6025,35 +6013,48 @@ def ReadInFileWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0
60256013
outfsize = fp.tell()
60266014
fp.seek(filestart, 0)
60276015
currentfilepos = fp.tell()
6016+
if(not isinstance(infile, FileLikeAdapter)):
6017+
6018+
# For uncompressed: optional mmap
6019+
mm = None
6020+
try:
6021+
base = _extract_base_fp(fp)
6022+
if base is not None:
6023+
mm = mmap.mmap(base.fileno(), 0, access=mmap.ACCESS_READ if "r" in mode else mmap.ACCESS_WRITE)
6024+
except Exception:
6025+
mm = None # fallback to normal file stream
6026+
readfp = FileLikeAdapter(fp, mode="rb", mm=mm)
6027+
else:
6028+
readfp = fp
60286029
ArchiveList = []
60296030
while True:
60306031
if currentfilepos >= outfsize: # stop when function signals False
60316032
break
6032-
oldfppos = fp.tell()
6033-
compresscheck = CheckCompressionType(fp, formatspecs, currentfilepos, False)
6033+
oldfppos = readfp.tell()
6034+
compresscheck = CheckCompressionType(readfp, formatspecs, currentfilepos, False)
60346035
if(IsNestedDict(formatspecs) and compresscheck in formatspecs):
60356036
pass
60366037
else:
6037-
checkcompressfile = CheckCompressionSubType(fp, formatspecs, currentfilepos, False)
6038+
checkcompressfile = CheckCompressionSubType(readfp, formatspecs, currentfilepos, False)
60386039
if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
60396040
pass
60406041
else:
60416042
break
6042-
fp.seek(oldfppos, 0)
6043+
readfp.seek(oldfppos, 0)
60436044
if(compresscheck in formatspecs):
60446045
if currentfilepos >= outfsize: # stop when function signals False
60456046
break
6046-
oldfppos = fp.tell()
6047-
compresscheck = CheckCompressionType(fp, formatspecs, currentfilepos, False)
6047+
oldfppos = readfp.tell()
6048+
compresscheck = CheckCompressionType(readfp, formatspecs, currentfilepos, False)
60486049
if(IsNestedDict(formatspecs) and compresscheck in formatspecs):
60496050
informatspecs = formatspecs[compresscheck]
60506051
else:
60516052
break
6052-
fp.seek(oldfppos, 0)
6053-
ArchiveList.append(ReadFileDataWithContentToList(fp, currentfilepos, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, informatspecs, seektoend))
6054-
currentfilepos = fp.tell()
6053+
readfp.seek(oldfppos, 0)
6054+
ArchiveList.append(ReadFileDataWithContentToList(readfp, currentfilepos, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, informatspecs, seektoend))
6055+
currentfilepos = readfp.tell()
60556056
else:
6056-
infp = UncompressFileAlt(fp, formatspecs, currentfilepos)
6057+
infp = UncompressFileAlt(readfp, formatspecs, currentfilepos)
60576058
infp.seek(0, 0)
60586059
currentinfilepos = infp.tell()
60596060
try:
@@ -6076,8 +6077,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0
60766077
infp.seek(oldinfppos, 0)
60776078
ArchiveList.append(ReadFileDataWithContentToList(infp, currentinfilepos, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, informatspecs, seektoend))
60786079
currentinfilepos = infp.tell()
6079-
infp.close()
6080-
currentfilepos = fp.tell()
6080+
currentfilepos = readfp.tell()
60816081
return ArchiveList
60826082

60836083

@@ -6088,7 +6088,7 @@ def ReadInMultipleFileWithContentToList(infile, fmttype="auto", filestart=0, see
60886088
infile = [infile]
60896089
outretval = {}
60906090
for curfname in infile:
6091-
outretval[curfname] = ReadInFileWithContentToList(curfname, fmttype, filestart, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend)
6091+
outretval.append(ReadInFileWithContentToList(curfname, fmttype, filestart, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend))
60926092
return outretval
60936093

60946094
def ReadInMultipleFilesWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0, seekend=0, listonly=False, contentasfile=True, uncompress=True, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False):
@@ -9528,6 +9528,7 @@ def myfileobj(self):
95289528
return self.file
95299529

95309530

9531+
95319532
# ========= mmap helpers & openers =========
95329533

95339534
def _maybe_make_mmap(fp_like, mode, use_mmap=False, mmap_size=None):
@@ -10511,9 +10512,9 @@ def MultipleCatFileToArray(infile, fmttype="auto", filestart=0, seekstart=0, see
1051110512
pass
1051210513
else:
1051310514
infile = [infile]
10514-
outretval = {}
10515+
outretval = []
1051510516
for curfname in infile:
10516-
outretval[curfname] = CatFileToArray(curfname, fmttype, filestart, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend, returnfp)
10517+
outretval.append(CatFileToArray(curfname, fmttype, filestart, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend, returnfp))
1051710518
return outretval
1051810519

1051910520
def MultipleCatFilesToArray(infile, fmttype="auto", filestart=0, seekstart=0, seekend=0, listonly=False, contentasfile=True, uncompress=True, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, returnfp=False):

0 commit comments

Comments
 (0)