PyCatFile 0.15.8__tar.gz → 0.15.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCatFile
3
- Version: 0.15.8
3
+ Version: 0.15.12
4
4
  Summary: A tar like file format name catfile after unix cat command (concatenate files) .
5
5
  Home-page: https://github.com/GameMaker2k/PyCatFile
6
6
  Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCatFile
3
- Version: 0.15.8
3
+ Version: 0.15.12
4
4
  Summary: A tar like file format name catfile after unix cat command (concatenate files) .
5
5
  Home-page: https://github.com/GameMaker2k/PyCatFile
6
6
  Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: catfile.py - Last Update: 12/14/2024 Ver. 0.15.8 RC 1 - Author: cooldude2k $
17
+ $FileInfo: catfile.py - Last Update: 12/20/2024 Ver. 0.15.12 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
@@ -14,13 +14,32 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: neocatfile.py - Last Update: 12/14/2024 Ver. 0.15.8 RC 1 - Author: cooldude2k $
17
+ $FileInfo: neocatfile.py - Last Update: 12/20/2024 Ver. 0.15.12 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
21
21
  import argparse
22
22
  import pycatfile
23
23
 
24
+ __project__ = pycatfile.__project__
25
+ __program_name__ = pycatfile.__program_name__
26
+ __file_format_name__ = pycatfile.__file_format_name__
27
+ __file_format_lower__ = pycatfile.__file_format_lower__
28
+ __file_format_magic__ = pycatfile.__file_format_magic__
29
+ __file_format_len__ = pycatfile.__file_format_len__
30
+ __file_format_hex__ = pycatfile.__file_format_hex__
31
+ __file_format_delimiter__ = pycatfile.__file_format_delimiter__
32
+ __file_format_list__ = pycatfile.__file_format_list__
33
+ __use_new_style__ = pycatfile.__use_new_style__
34
+ __use_advanced_list__ = pycatfile.__use_advanced_list__
35
+ __use_alt_inode__ = pycatfile.__use_alt_inode__
36
+ __project_url__ = pycatfile.__project_url__
37
+ __version_info__ = pycatfile.__version_info__
38
+ __version_date_info__ = pycatfile.__version_date_info__
39
+ __version_date__ = pycatfile.__version_date__
40
+ __version_date_plusrc__ = pycatfile.__version_date_plusrc__
41
+ __version__ = pycatfile.__version__
42
+
24
43
  # Compatibility layer for Python 2 and 3 input
25
44
  try:
26
45
  input = raw_input
@@ -34,7 +53,8 @@ py7zr_support = pycatfile.py7zr_support
34
53
  # Set up the argument parser
35
54
  argparser = argparse.ArgumentParser(
36
55
  description="Manipulates concatenated files for various operations like creation, extraction, and validation.")
37
- argparser.add_argument("-V", "--version", action="version", version=__program_name__ + " " + __version__, help="Displays the program's version.")
56
+ argparser.add_argument("-V", "--version", action="version", version="{0} {1}".format(
57
+ __program_name__, __version__), help="Displays the program's version.")
38
58
  argparser.add_argument("-i", "--input", required=True,
39
59
  help="Specifies input file(s) for processing.")
40
60
  argparser.add_argument(
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: pycatfile.py - Last Update: 12/14/2024 Ver. 0.15.8 RC 1 - Author: cooldude2k $
17
+ $FileInfo: pycatfile.py - Last Update: 12/20/2024 Ver. 0.15.12 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
@@ -304,12 +304,12 @@ __file_format_dict__ = {'format_name': __file_format_name__, 'format_magic': __f
304
304
  'format_delimiter': __file_format_delimiter__, 'format_ver': __file_format_ver__, 'new_style': __use_new_style__, 'use_advanced_list': __use_advanced_list__, 'use_alt_inode': __use_alt_inode__}
305
305
  __project__ = __program_name__
306
306
  __project_url__ = "https://github.com/GameMaker2k/PyCatFile"
307
- __version_info__ = (0, 15, 8, "RC 1", 1)
308
- __version_date_info__ = (2024, 12, 14, "RC 1", 1)
307
+ __version_info__ = (0, 15, 12, "RC 1", 1)
308
+ __version_date_info__ = (2024, 12, 20, "RC 1", 1)
309
309
  __version_date__ = str(__version_date_info__[0]) + "." + str(
310
310
  __version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
311
311
  __revision__ = __version_info__[3]
312
- __revision_id__ = "$Id: d7609469045e54d12bd85a24dc8a90415987d52d $"
312
+ __revision_id__ = "$Id: 1462baae55cec6c1aac531873eaeb2b3efe154d4 $"
313
313
  if(__version_info__[4] is not None):
314
314
  __version_date_plusrc__ = __version_date__ + \
315
315
  "-" + str(__version_date_info__[4])
@@ -1516,16 +1516,21 @@ def ValidateFileChecksum(infile, checksumtype="crc32", inchecksum="0", formatspe
1516
1516
 
1517
1517
 
1518
1518
  def ReadTillNullByteOld(fp, delimiter=__file_format_dict__['format_delimiter']):
1519
- if(not hasattr(fp, "read")):
1519
+ if not hasattr(fp, "read"):
1520
1520
  return False
1521
- curbyte = b""
1522
- curfullbyte = b""
1521
+ curfullbyte = bytearray()
1523
1522
  nullbyte = delimiter.encode("UTF-8")
1524
- while(True):
1523
+ dellen = len(nullbyte)
1524
+ while True:
1525
1525
  curbyte = fp.read(1)
1526
- if(curbyte == nullbyte or not curbyte):
1526
+ if not curbyte: # End of file or no more data
1527
+ break
1528
+ curfullbyte.extend(curbyte)
1529
+ # Check if the end of the buffer matches our delimiter
1530
+ if len(curfullbyte) >= dellen and curfullbyte[-dellen:] == nullbyte:
1531
+ # Remove the delimiter from the returned bytes
1532
+ curfullbyte = curfullbyte[:-dellen]
1527
1533
  break
1528
- curfullbyte = curfullbyte + curbyte
1529
1534
  return curfullbyte.decode('UTF-8')
1530
1535
 
1531
1536
 
@@ -1581,25 +1586,31 @@ def ReadUntilNullByteAlt(fp, delimiter=__file_format_dict__['format_delimiter'],
1581
1586
 
1582
1587
 
1583
1588
  def ReadTillNullByte(fp, delimiter=__file_format_dict__['format_delimiter'], max_read=1024000):
1584
- if(not hasattr(fp, "read")):
1589
+ if not hasattr(fp, "read"):
1585
1590
  return False
1586
1591
  curfullbyte = bytearray()
1587
1592
  nullbyte = delimiter.encode("UTF-8")
1593
+ dellen = len(nullbyte)
1588
1594
  total_read = 0 # Track the total number of bytes read
1589
1595
  while True:
1590
1596
  curbyte = fp.read(1)
1591
- if curbyte == nullbyte or not curbyte:
1597
+ if not curbyte: # End of file or no more data
1592
1598
  break
1593
1599
  curfullbyte.extend(curbyte)
1594
1600
  total_read += 1
1601
+ # Check if the end of the buffer matches the delimiter
1602
+ if len(curfullbyte) >= dellen and curfullbyte[-dellen:] == nullbyte:
1603
+ # Remove the delimiter from the returned bytes
1604
+ curfullbyte = curfullbyte[:-dellen]
1605
+ break
1606
+ # Check if we have exceeded the max read limit
1595
1607
  if total_read >= max_read:
1596
- raise MemoryError(
1597
- "Maximum read limit reached without finding the delimiter.")
1608
+ raise MemoryError("Maximum read limit reached without finding the delimiter.")
1598
1609
  # Decode the full byte array to string once out of the loop
1599
1610
  try:
1600
1611
  return curfullbyte.decode('UTF-8')
1601
1612
  except UnicodeDecodeError:
1602
- # Handle potential partial UTF-8 characters
1613
+ # Handle potential partial UTF-8 characters at the end
1603
1614
  for i in range(1, 4):
1604
1615
  try:
1605
1616
  return curfullbyte[:-i].decode('UTF-8')
@@ -2453,17 +2464,17 @@ def MakeEmptyFilePointer(fp, checksumtype="crc32", formatspecs=__file_format_dic
2453
2464
  return fp
2454
2465
 
2455
2466
 
2456
- def MakeEmptyFile(outfile, compression="auto", compressionlevel=None, checksumtype="crc32", formatspecs=__file_format_dict__, returnfp=False):
2467
+ def MakeEmptyFile(outfile, compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", formatspecs=__file_format_dict__, returnfp=False):
2457
2468
  formatspecs = FormatSpecsListToDict(formatspecs)
2458
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
2469
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
2459
2470
  if(os.path.exists(outfile)):
2460
2471
  try:
2461
2472
  os.unlink(outfile)
2462
2473
  except OSError:
2463
2474
  pass
2464
- if(outfile == "-"):
2475
+ if(outfile == "-" or outfile is None):
2465
2476
  verbose = False
2466
- catfpfp = BytesIO()
2477
+ catfp = BytesIO()
2467
2478
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
2468
2479
  catfp = outfile
2469
2480
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
@@ -2475,7 +2486,7 @@ def MakeEmptyFile(outfile, compression="auto", compressionlevel=None, checksumty
2475
2486
  compresswholefile = True
2476
2487
  catfp = CompressOpenFile(outfile, True, compressionlevel)
2477
2488
  catfp = AppendFileHeader(catfp, 0, checksumtype, formatspecs)
2478
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
2489
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
2479
2490
  catfp = CompressArchiveFile(
2480
2491
  catfp, compression, compressionlevel, formatspecs)
2481
2492
  try:
@@ -2494,6 +2505,11 @@ def MakeEmptyFile(outfile, compression="auto", compressionlevel=None, checksumty
2494
2505
  shutil.copyfileobj(catfp, sys.stdout.buffer)
2495
2506
  else:
2496
2507
  shutil.copyfileobj(catfp, sys.stdout)
2508
+ elif(outfile is None):
2509
+ catfp.seek(0, 0)
2510
+ outvar = catfp.read()
2511
+ catfp.close()
2512
+ return outvar
2497
2513
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
2498
2514
  catfp = CompressArchiveFile(
2499
2515
  catfp, compression, compressionlevel, formatspecs)
@@ -2694,9 +2710,13 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2694
2710
  getfdev = GetDevMajorMinor(fdev)
2695
2711
  fdev_minor = getfdev[0]
2696
2712
  fdev_major = getfdev[1]
2697
- if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
2713
+ # Types that should be considered zero-length in the archive context:
2714
+ zero_length_types = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13}
2715
+ # Types that have actual data to read:
2716
+ data_types = {0, 7, 12}
2717
+ if ftype in zero_length_types:
2698
2718
  fsize = format(int("0"), 'x').lower()
2699
- elif(ftype == 0 or ftype == 7):
2719
+ elif ftype in data_types:
2700
2720
  fsize = format(int(fstatinfo.st_size), 'x').lower()
2701
2721
  else:
2702
2722
  fsize = format(int(fstatinfo.st_size)).lower()
@@ -2746,7 +2766,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2746
2766
  fcsize = format(int(0), 'x').lower()
2747
2767
  fcontents = BytesIO()
2748
2768
  chunk_size = 1024
2749
- if(ftype == 0 or ftype == 7):
2769
+ if ftype in data_types:
2750
2770
  with open(fname, "rb") as fpc:
2751
2771
  shutil.copyfileobj(fpc, fcontents)
2752
2772
  if(not compresswholefile):
@@ -2838,7 +2858,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2838
2858
  fcontents.seek(0, 0)
2839
2859
  ftypehex = format(ftype, 'x').lower()
2840
2860
  catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
2841
- fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+1"]
2861
+ fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+"+str(len(formatspecs['format_delimiter']))]
2842
2862
  fp = AppendFileHeaderWithContent(
2843
2863
  fp, catoutlist, extradata, fcontents.read(), checksumtype, formatspecs)
2844
2864
  if(numfiles > 0):
@@ -2919,15 +2939,15 @@ def AppendInFileWithContent(infile, fp, dirlistfromtxt=False, filevalues=[], ext
2919
2939
 
2920
2940
  def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, compression="auto", compresswholefile=True, compressionlevel=None, filevalues=[], extradata=[], followlink=False, checksumtype="crc32", formatspecs=__file_format_dict__, verbose=False, returnfp=False):
2921
2941
  formatspecs = FormatSpecsListToDict(formatspecs)
2922
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
2942
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
2923
2943
  if(os.path.exists(outfile)):
2924
2944
  try:
2925
2945
  os.unlink(outfile)
2926
2946
  except OSError:
2927
2947
  pass
2928
- if(outfile == "-"):
2948
+ if(outfile == "-" or outfile is None):
2929
2949
  verbose = False
2930
- catfpfp = BytesIO()
2950
+ catfp = BytesIO()
2931
2951
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
2932
2952
  catfp = outfile
2933
2953
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
@@ -2940,7 +2960,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, comp
2940
2960
  catfp = CompressOpenFile(outfile, compresswholefile, compressionlevel)
2941
2961
  catfp = AppendFilesWithContent(infiles, catfp, dirlistfromtxt, filevalues, extradata, compression,
2942
2962
  compresswholefile, compressionlevel, followlink, checksumtype, formatspecs, verbose)
2943
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
2963
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
2944
2964
  catfp = CompressArchiveFile(
2945
2965
  catfp, compression, compressionlevel, formatspecs)
2946
2966
  try:
@@ -2959,6 +2979,11 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, comp
2959
2979
  shutil.copyfileobj(catfp, sys.stdout.buffer)
2960
2980
  else:
2961
2981
  shutil.copyfileobj(catfp, sys.stdout)
2982
+ elif(outfile is None):
2983
+ catfp.seek(0, 0)
2984
+ outvar = catfp.read()
2985
+ catfp.close()
2986
+ return outvar
2962
2987
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
2963
2988
  catfp = CompressArchiveFile(
2964
2989
  catfp, compression, compressionlevel, formatspecs)
@@ -2974,15 +2999,15 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, comp
2974
2999
 
2975
3000
  def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, compression="auto", compresswholefile=True, compressionlevel=None, filevalues=[], extradata=[], followlink=False, checksumtype="crc32", formatspecs=__file_format_dict__, verbose=False, returnfp=False):
2976
3001
  formatspecs = FormatSpecsListToDict(formatspecs)
2977
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
3002
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
2978
3003
  if(os.path.exists(outfile)):
2979
3004
  try:
2980
3005
  os.unlink(outfile)
2981
3006
  except OSError:
2982
3007
  pass
2983
- if(outfile == "-"):
3008
+ if(outfile == "-" or outfile is None):
2984
3009
  verbose = False
2985
- catfpfp = BytesIO()
3010
+ catfp = BytesIO()
2986
3011
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
2987
3012
  catfp = outfile
2988
3013
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
@@ -2995,7 +3020,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, compr
2995
3020
  catfp = CompressOpenFile(outfile, compresswholefile, compressionlevel)
2996
3021
  catfp = AppendListsWithContent(inlist, catfp, dirlistfromtxt, filevalues, extradata, compression,
2997
3022
  compresswholefile, compressionlevel, followlink, checksumtype, formatspecs, verbose)
2998
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
3023
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
2999
3024
  catfp = CompressArchiveFile(
3000
3025
  catfp, compression, compressionlevel, formatspecs)
3001
3026
  try:
@@ -3014,6 +3039,11 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, compr
3014
3039
  shutil.copyfileobj(catfp, sys.stdout.buffer)
3015
3040
  else:
3016
3041
  shutil.copyfileobj(catfp, sys.stdout)
3042
+ elif(outfile is None):
3043
+ catfp.seek(0, 0)
3044
+ outvar = catfp.read()
3045
+ catfp.close()
3046
+ return outvar
3017
3047
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
3018
3048
  catfp = CompressArchiveFile(
3019
3049
  catfp, compression, compressionlevel, formatspecs)
@@ -3714,7 +3744,7 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3714
3744
  formatspecs = FormatSpecsListToDict(formatspecs)
3715
3745
  advancedlist = formatspecs['use_advanced_list']
3716
3746
  altinode = formatspecs['use_alt_inode']
3717
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
3747
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
3718
3748
  outfile = RemoveWindowsPath(outfile)
3719
3749
  checksumtype = checksumtype.lower()
3720
3750
  if(not CheckSumSupport(checksumtype, hashlib_guaranteed)):
@@ -3728,13 +3758,13 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3728
3758
  if(verbose):
3729
3759
  logging.basicConfig(format="%(message)s",
3730
3760
  stream=sys.stdout, level=logging.DEBUG)
3731
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
3761
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
3732
3762
  if(os.path.exists(outfile)):
3733
3763
  try:
3734
3764
  os.unlink(outfile)
3735
3765
  except OSError:
3736
3766
  pass
3737
- if(outfile == "-"):
3767
+ if(outfile == "-" or outfile is None):
3738
3768
  verbose = False
3739
3769
  catfp = BytesIO()
3740
3770
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
@@ -3803,8 +3833,8 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3803
3833
  ftype = 0
3804
3834
  if(hasattr(os.path, "isjunction") and os.path.isjunction(fname)):
3805
3835
  ftype = 13
3806
- elif(fstatinfo.st_blocks * 512 < fstatinfo.st_size):
3807
- ftype = 12
3836
+ #elif(fstatinfo.st_blocks * 512 < fstatinfo.st_size):
3837
+ # ftype = 12
3808
3838
  elif(stat.S_ISREG(fpremode)):
3809
3839
  ftype = 0
3810
3840
  elif(stat.S_ISLNK(fpremode)):
@@ -3864,9 +3894,13 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3864
3894
  getfdev = GetDevMajorMinor(fdev)
3865
3895
  fdev_minor = getfdev[0]
3866
3896
  fdev_major = getfdev[1]
3867
- if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
3897
+ # Types that should be considered zero-length in the archive context:
3898
+ zero_length_types = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13}
3899
+ # Types that have actual data to read:
3900
+ data_types = {0, 7, 12}
3901
+ if ftype in zero_length_types:
3868
3902
  fsize = format(int("0"), 'x').lower()
3869
- elif(ftype == 0 or ftype == 7):
3903
+ elif ftype in data_types:
3870
3904
  fsize = format(int(fstatinfo.st_size), 'x').lower()
3871
3905
  else:
3872
3906
  fsize = format(int(fstatinfo.st_size)).lower()
@@ -3915,7 +3949,7 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3915
3949
  fcompression = ""
3916
3950
  fcsize = format(int(0), 'x').lower()
3917
3951
  fcontents = BytesIO()
3918
- if(ftype == 0 or ftype == 7):
3952
+ if ftype in data_types:
3919
3953
  with open(fname, "rb") as fpc:
3920
3954
  shutil.copyfileobj(fpc, fcontents)
3921
3955
  if(not compresswholefile):
@@ -4007,14 +4041,14 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
4007
4041
  fcontents.seek(0, 0)
4008
4042
  ftypehex = format(ftype, 'x').lower()
4009
4043
  catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
4010
- fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+1"]
4044
+ fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+"+str(len(formatspecs['format_delimiter']))]
4011
4045
  catfp = AppendFileHeaderWithContent(
4012
4046
  catfp, catoutlist, extradata, fcontents.read(), checksumtype, formatspecs)
4013
4047
  fcontents.close()
4014
4048
  if(numfiles > 0):
4015
4049
  catfp.write(AppendNullBytes(
4016
4050
  [0, 0], formatspecs['format_delimiter']).encode("UTF-8"))
4017
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
4051
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
4018
4052
  catfp = CompressArchiveFile(
4019
4053
  catfp, compression, compressionlevel, formatspecs)
4020
4054
  try:
@@ -4033,6 +4067,11 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
4033
4067
  shutil.copyfileobj(catfp, sys.stdout.buffer)
4034
4068
  else:
4035
4069
  shutil.copyfileobj(catfp, sys.stdout)
4070
+ elif(outfile is None):
4071
+ catfp.seek(0, 0)
4072
+ outvar = catfp.read()
4073
+ catfp.close()
4074
+ return outvar
4036
4075
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
4037
4076
  catfp = CompressArchiveFile(
4038
4077
  catfp, compression, compressionlevel, formatspecs)
@@ -4066,7 +4105,7 @@ create_alias_function("Pack", __file_format_name__,
4066
4105
 
4067
4106
  def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False):
4068
4107
  formatspecs = FormatSpecsListToDict(formatspecs)
4069
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4108
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4070
4109
  outfile = RemoveWindowsPath(outfile)
4071
4110
  checksumtype = checksumtype.lower()
4072
4111
  if(not CheckSumSupport(checksumtype, hashlib_guaranteed)):
@@ -4080,13 +4119,13 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4080
4119
  if(verbose):
4081
4120
  logging.basicConfig(format="%(message)s",
4082
4121
  stream=sys.stdout, level=logging.DEBUG)
4083
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4122
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4084
4123
  if(os.path.exists(outfile)):
4085
4124
  try:
4086
4125
  os.unlink(outfile)
4087
4126
  except OSError:
4088
4127
  pass
4089
- if(outfile == "-"):
4128
+ if(outfile == "-" or outfile is None):
4090
4129
  verbose = False
4091
4130
  catfp = BytesIO()
4092
4131
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
@@ -4194,9 +4233,13 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4194
4233
  fdev = format(int(MakeDevAlt(member.devmajor, member.devminor)), 'x').lower()
4195
4234
  fdev_minor = format(int(member.devminor), 'x').lower()
4196
4235
  fdev_major = format(int(member.devmajor), 'x').lower()
4197
- if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
4236
+ # Types that should be considered zero-length in the archive context:
4237
+ zero_length_types = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13}
4238
+ # Types that have actual data to read:
4239
+ data_types = {0, 7, 12}
4240
+ if ftype in zero_length_types:
4198
4241
  fsize = format(int("0"), 'x').lower()
4199
- elif(ftype == 0 or ftype == 7):
4242
+ elif ftype in data_types:
4200
4243
  fsize = format(int(member.size), 'x').lower()
4201
4244
  else:
4202
4245
  fsize = format(int(member.size), 'x').lower()
@@ -4216,7 +4259,7 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4216
4259
  fcompression = ""
4217
4260
  fcsize = format(int(0), 'x').lower()
4218
4261
  fcontents = BytesIO()
4219
- if(ftype == 0 or ftype == 7):
4262
+ if ftype in data_types:
4220
4263
  with tarfp.extractfile(member) as fpc:
4221
4264
  shutil.copyfileobj(fpc, fcontents)
4222
4265
  if(not compresswholefile):
@@ -4264,14 +4307,14 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4264
4307
  fcontents.seek(0, 0)
4265
4308
  ftypehex = format(ftype, 'x').lower()
4266
4309
  catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
4267
- fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+1"]
4310
+ fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+"+str(len(formatspecs['format_delimiter']))]
4268
4311
  catfp = AppendFileHeaderWithContent(
4269
4312
  catfp, catoutlist, extradata, fcontents.read(), checksumtype, formatspecs)
4270
4313
  fcontents.close()
4271
4314
  if(numfiles > 0):
4272
4315
  catfp.write(AppendNullBytes(
4273
4316
  [0, 0], formatspecs['format_delimiter']).encode("UTF-8"))
4274
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
4317
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
4275
4318
  catfp = CompressArchiveFile(
4276
4319
  catfp, compression, compressionlevel, formatspecs)
4277
4320
  try:
@@ -4290,6 +4333,11 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4290
4333
  shutil.copyfileobj(catfp, sys.stdout.buffer)
4291
4334
  else:
4292
4335
  shutil.copyfileobj(catfp, sys.stdout)
4336
+ elif(outfile is None):
4337
+ catfp.seek(0, 0)
4338
+ outvar = catfp.read()
4339
+ catfp.close()
4340
+ return outvar
4293
4341
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
4294
4342
  catfp = CompressArchiveFile(
4295
4343
  catfp, compression, compressionlevel, formatspecs)
@@ -4309,7 +4357,7 @@ create_alias_function("Pack", __file_format_name__,
4309
4357
 
4310
4358
  def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False):
4311
4359
  formatspecs = FormatSpecsListToDict(formatspecs)
4312
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4360
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4313
4361
  outfile = RemoveWindowsPath(outfile)
4314
4362
  checksumtype = checksumtype.lower()
4315
4363
  if(not CheckSumSupport(checksumtype, hashlib_guaranteed)):
@@ -4323,13 +4371,13 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4323
4371
  if(verbose):
4324
4372
  logging.basicConfig(format="%(message)s",
4325
4373
  stream=sys.stdout, level=logging.DEBUG)
4326
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4374
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4327
4375
  if(os.path.exists(outfile)):
4328
4376
  try:
4329
4377
  os.unlink(outfile)
4330
4378
  except OSError:
4331
4379
  pass
4332
- if(outfile == "-"):
4380
+ if(outfile == "-" or outfile is None):
4333
4381
  verbose = False
4334
4382
  catfp = BytesIO()
4335
4383
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
@@ -4531,14 +4579,14 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4531
4579
  fcontents.seek(0, 0)
4532
4580
  ftypehex = format(ftype, 'x').lower()
4533
4581
  catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
4534
- fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+1"]
4582
+ fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+"+str(len(formatspecs['format_delimiter']))]
4535
4583
  catfp = AppendFileHeaderWithContent(
4536
4584
  catfp, catoutlist, extradata, fcontents.read(), checksumtype, formatspecs)
4537
4585
  fcontents.close()
4538
4586
  if(numfiles > 0):
4539
4587
  catfp.write(AppendNullBytes(
4540
4588
  [0, 0], formatspecs['format_delimiter']).encode("UTF-8"))
4541
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
4589
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
4542
4590
  catfp = CompressArchiveFile(
4543
4591
  catfp, compression, compressionlevel, formatspecs)
4544
4592
  try:
@@ -4557,6 +4605,11 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4557
4605
  shutil.copyfileobj(catfp, sys.stdout.buffer)
4558
4606
  else:
4559
4607
  shutil.copyfileobj(catfp, sys.stdout)
4608
+ elif(outfile is None):
4609
+ catfp.seek(0, 0)
4610
+ outvar = catfp.read()
4611
+ catfp.close()
4612
+ return outvar
4560
4613
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
4561
4614
  catfp = CompressArchiveFile(
4562
4615
  catfp, compression, compressionlevel, formatspecs)
@@ -4580,7 +4633,7 @@ if(not rarfile_support):
4580
4633
  if(rarfile_support):
4581
4634
  def PackArchiveFileFromRarFile(infile, outfile, compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False):
4582
4635
  formatspecs = FormatSpecsListToDict(formatspecs)
4583
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4636
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4584
4637
  outfile = RemoveWindowsPath(outfile)
4585
4638
  checksumtype = checksumtype.lower()
4586
4639
  if(not CheckSumSupport(checksumtype, hashlib_guaranteed)):
@@ -4594,13 +4647,13 @@ if(rarfile_support):
4594
4647
  if(verbose):
4595
4648
  logging.basicConfig(format="%(message)s",
4596
4649
  stream=sys.stdout, level=logging.DEBUG)
4597
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4650
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4598
4651
  if(os.path.exists(outfile)):
4599
4652
  try:
4600
4653
  os.unlink(outfile)
4601
4654
  except OSError:
4602
4655
  pass
4603
- if(outfile == "-"):
4656
+ if(outfile == "-" or outfile is None):
4604
4657
  verbose = False
4605
4658
  catfp = BytesIO()
4606
4659
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
@@ -4829,14 +4882,14 @@ if(rarfile_support):
4829
4882
  fcontents.seek(0, 0)
4830
4883
  ftypehex = format(ftype, 'x').lower()
4831
4884
  catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
4832
- fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+1"]
4885
+ fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+"+str(len(formatspecs['format_delimiter']))]
4833
4886
  catfp = AppendFileHeaderWithContent(
4834
4887
  catfp, catoutlist, extradata, fcontents.read(), checksumtype, formatspecs)
4835
4888
  fcontents.close()
4836
4889
  if(numfiles > 0):
4837
4890
  catfp.write(AppendNullBytes(
4838
4891
  [0, 0], formatspecs['format_delimiter']).encode("UTF-8"))
4839
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
4892
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
4840
4893
  catfp = CompressArchiveFile(
4841
4894
  catfp, compression, compressionlevel, formatspecs)
4842
4895
  try:
@@ -4855,6 +4908,11 @@ if(rarfile_support):
4855
4908
  shutil.copyfileobj(catfp, sys.stdout.buffer)
4856
4909
  else:
4857
4910
  shutil.copyfileobj(catfp, sys.stdout)
4911
+ elif(outfile is None):
4912
+ catfp.seek(0, 0)
4913
+ outvar = catfp.read()
4914
+ catfp.close()
4915
+ return outvar
4858
4916
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
4859
4917
  catfp = CompressArchiveFile(
4860
4918
  catfp, compression, compressionlevel, formatspecs)
@@ -4877,7 +4935,7 @@ if(not py7zr_support):
4877
4935
  if(py7zr_support):
4878
4936
  def PackArchiveFileFromSevenZipFile(infile, outfile, compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False):
4879
4937
  formatspecs = FormatSpecsListToDict(formatspecs)
4880
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4938
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4881
4939
  outfile = RemoveWindowsPath(outfile)
4882
4940
  checksumtype = checksumtype.lower()
4883
4941
  if(not CheckSumSupport(checksumtype, hashlib_guaranteed)):
@@ -4891,13 +4949,13 @@ if(py7zr_support):
4891
4949
  if(verbose):
4892
4950
  logging.basicConfig(format="%(message)s",
4893
4951
  stream=sys.stdout, level=logging.DEBUG)
4894
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4952
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
4895
4953
  if(os.path.exists(outfile)):
4896
4954
  try:
4897
4955
  os.unlink(outfile)
4898
4956
  except OSError:
4899
4957
  pass
4900
- if(outfile == "-"):
4958
+ if(outfile == "-" or outfile is None):
4901
4959
  verbose = False
4902
4960
  catfp = BytesIO()
4903
4961
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
@@ -5059,14 +5117,14 @@ if(py7zr_support):
5059
5117
  fcontents.seek(0, 0)
5060
5118
  ftypehex = format(ftype, 'x').lower()
5061
5119
  catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fcompression,
5062
- fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+1"]
5120
+ fcsize, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev, fdev_minor, fdev_major, "+"+str(len(formatspecs['format_delimiter']))]
5063
5121
  catfp = AppendFileHeaderWithContent(
5064
5122
  catfp, catoutlist, extradata, fcontents.read(), checksumtype, formatspecs)
5065
5123
  fcontents.close()
5066
5124
  if(numfiles > 0):
5067
5125
  catfp.write(AppendNullBytes(
5068
5126
  [0, 0], formatspecs['format_delimiter']).encode("UTF-8"))
5069
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
5127
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
5070
5128
  catfp = CompressArchiveFile(
5071
5129
  catfp, compression, compressionlevel, formatspecs)
5072
5130
  try:
@@ -5085,6 +5143,11 @@ if(py7zr_support):
5085
5143
  shutil.copyfileobj(catfp, sys.stdout.buffer)
5086
5144
  else:
5087
5145
  shutil.copyfileobj(catfp, sys.stdout)
5146
+ elif(outfile is None):
5147
+ catfp.seek(0, 0)
5148
+ outvar = catfp.read()
5149
+ catfp.close()
5150
+ return outvar
5088
5151
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
5089
5152
  catfp = CompressArchiveFile(
5090
5153
  catfp, compression, compressionlevel, formatspecs)
@@ -5157,6 +5220,14 @@ def ArchiveFileSeekToFileNum(infile, seekto=0, listonly=False, contentasfile=Tru
5157
5220
  if(not catfp):
5158
5221
  return False
5159
5222
  catfp.seek(0, 0)
5223
+ elif(isinstance(infile, bytes)):
5224
+ catfp = BytesIO()
5225
+ catfp.write(infile)
5226
+ catfp.seek(0, 0)
5227
+ catfp = UncompressArchiveFile(catfp, formatspecs)
5228
+ if(not catfp):
5229
+ return False
5230
+ catfp.seek(0, 0)
5160
5231
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5161
5232
  catfp = download_file_from_internet_file(infile)
5162
5233
  catfp.seek(0, 0)
@@ -5416,6 +5487,14 @@ def ArchiveFileSeekToFileName(infile, seekfile=None, listonly=False, contentasfi
5416
5487
  if(not catfp):
5417
5488
  return False
5418
5489
  catfp.seek(0, 0)
5490
+ elif(isinstance(infile, bytes)):
5491
+ catfp = BytesIO()
5492
+ catfp.write(infile)
5493
+ catfp.seek(0, 0)
5494
+ catfp = UncompressArchiveFile(catfp, formatspecs)
5495
+ if(not catfp):
5496
+ return False
5497
+ catfp.seek(0, 0)
5419
5498
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5420
5499
  catfp = download_file_from_internet_file(infile)
5421
5500
  catfp = UncompressArchiveFile(catfp, formatspecs)
@@ -5688,6 +5767,14 @@ def ArchiveFileValidate(infile, formatspecs=__file_format_dict__, verbose=False,
5688
5767
  if(not catfp):
5689
5768
  return False
5690
5769
  catfp.seek(0, 0)
5770
+ elif(isinstance(infile, bytes)):
5771
+ catfp = BytesIO()
5772
+ catfp.write(infile)
5773
+ catfp.seek(0, 0)
5774
+ catfp = UncompressArchiveFile(catfp, formatspecs)
5775
+ if(not catfp):
5776
+ return False
5777
+ catfp.seek(0, 0)
5691
5778
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5692
5779
  catfp = download_file_from_internet_file(infile)
5693
5780
  catfp = UncompressArchiveFile(catfp, formatspecs)
@@ -5967,6 +6054,14 @@ def ArchiveFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentas
5967
6054
  if(not catfp):
5968
6055
  return False
5969
6056
  catfp.seek(0, 0)
6057
+ elif(isinstance(infile, bytes)):
6058
+ catfp = BytesIO()
6059
+ catfp.write(infile)
6060
+ catfp.seek(0, 0)
6061
+ catfp = UncompressArchiveFile(catfp, formatspecs)
6062
+ if(not catfp):
6063
+ return False
6064
+ catfp.seek(0, 0)
5970
6065
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5971
6066
  catfp = download_file_from_internet_file(infile)
5972
6067
  catfp = UncompressArchiveFile(catfp, formatspecs)
@@ -6442,8 +6537,8 @@ def ListDirToArrayAlt(infiles, dirlistfromtxt=False, followlink=False, listonly=
6442
6537
  ftype = 0
6443
6538
  if(hasattr(os.path, "isjunction") and os.path.isjunction(fname)):
6444
6539
  ftype = 13
6445
- elif(fstatinfo.st_blocks * 512 < fstatinfo.st_size):
6446
- ftype = 12
6540
+ #elif(fstatinfo.st_blocks * 512 < fstatinfo.st_size):
6541
+ # ftype = 12
6447
6542
  elif(stat.S_ISREG(fpremode)):
6448
6543
  ftype = 0
6449
6544
  elif(stat.S_ISLNK(fpremode)):
@@ -6504,9 +6599,15 @@ def ListDirToArrayAlt(infiles, dirlistfromtxt=False, followlink=False, listonly=
6504
6599
  getfdev = GetDevMajorMinor(fdev)
6505
6600
  fdev_minor = getfdev[0]
6506
6601
  fdev_major = getfdev[1]
6507
- if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
6602
+ # Types that should be considered zero-length in the archive context:
6603
+ zero_length_types = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13}
6604
+ # Types that have actual data to read:
6605
+ data_types = {0, 7, 12}
6606
+ if ftype in zero_length_types:
6508
6607
  fsize = "0"
6509
- if(ftype == 0 or ftype == 7):
6608
+ elif ftype in data_types:
6609
+ fsize = fstatinfo.st_size
6610
+ else:
6510
6611
  fsize = fstatinfo.st_size
6511
6612
  fatime = fstatinfo.st_atime
6512
6613
  fmtime = fstatinfo.st_mtime
@@ -6547,7 +6648,7 @@ def ListDirToArrayAlt(infiles, dirlistfromtxt=False, followlink=False, listonly=
6547
6648
  fcompression = ""
6548
6649
  fcsize = 0
6549
6650
  fcontents = BytesIO()
6550
- if(ftype == 0 or ftype == 7):
6651
+ if ftype in data_types:
6551
6652
  with open(fname, "rb") as fpc:
6552
6653
  shutil.copyfileobj(fpc, fcontents)
6553
6654
  if(followlink and (ftype == 1 or ftype == 2)):
@@ -6567,7 +6668,7 @@ def ListDirToArrayAlt(infiles, dirlistfromtxt=False, followlink=False, listonly=
6567
6668
  extrasizelen = len(extrasizestr)
6568
6669
  extrasizelenhex = format(extrasizelen, 'x').lower()
6569
6670
  catoutlist = [ftypehex, fname, flinkname, format(int(fsize), 'x').lower(), format(int(fatime), 'x').lower(), format(int(fmtime), 'x').lower(), format(int(fctime), 'x').lower(), format(int(fbtime), 'x').lower(), format(int(fmode), 'x').lower(), format(int(fwinattributes), 'x').lower(), fcompression, format(int(fcsize), 'x').lower(), format(int(fuid), 'x').lower(
6570
- ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+1", extrasizelenhex, format(catfextrafields, 'x').lower()]
6671
+ ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+"+str(len(formatspecs['format_delimiter'])), extrasizelenhex, format(catfextrafields, 'x').lower()]
6571
6672
  catoutlen = len(catoutlist) + len(extradata) + 3
6572
6673
  catoutlenhex = format(catoutlen, 'x').lower()
6573
6674
  catoutlist.insert(0, catoutlenhex)
@@ -6622,7 +6723,7 @@ def ListDirToArrayAlt(infiles, dirlistfromtxt=False, followlink=False, listonly=
6622
6723
  if(not contentasfile):
6623
6724
  fcontents = fcontents.read()
6624
6725
  catlist['ffilelist'].append({'fid': fileidnum, 'fidalt': fileidnum, 'fheadersize': int(catheaersize, 16), 'fhstart': catfhstart, 'fhend': catfhend, 'ftype': ftype, 'fname': fname, 'fbasedir': fbasedir, 'flinkname': flinkname, 'fsize': fsize, 'fatime': fatime, 'fmtime': fmtime, 'fctime': fctime, 'fbtime': fbtime, 'fmode': fmode, 'fchmode': fchmode, 'ftypemod': ftypemod, 'fwinattributes': fwinattributes, 'fcompression': fcompression, 'fcsize': fcsize, 'fuid': fuid, 'funame': funame, 'fgid': fgid, 'fgname': fgname, 'finode': finode, 'flinkcount': flinkcount,
6625
- 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+1", 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
6726
+ 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+"+str(len(formatspecs['format_delimiter'])), 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
6626
6727
  fileidnum = fileidnum + 1
6627
6728
  return catlist
6628
6729
 
@@ -6742,9 +6843,13 @@ def TarFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
6742
6843
  fdev = MakeDevAlt(member.devmajor, member.devminor)
6743
6844
  fdev_minor = member.devminor
6744
6845
  fdev_major = member.devmajor
6745
- if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
6846
+ # Types that should be considered zero-length in the archive context:
6847
+ zero_length_types = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13}
6848
+ # Types that have actual data to read:
6849
+ data_types = {0, 7, 12}
6850
+ if ftype in zero_length_types:
6746
6851
  fsize = "0"
6747
- elif(ftype == 0 or ftype == 7):
6852
+ elif ftype in data_types:
6748
6853
  fsize = member.size
6749
6854
  else:
6750
6855
  fsize = member.size
@@ -6764,7 +6869,7 @@ def TarFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
6764
6869
  fcompression = ""
6765
6870
  fcsize = 0
6766
6871
  fcontents = BytesIO()
6767
- if(ftype == 0 or ftype == 7):
6872
+ if ftype in data_types:
6768
6873
  with tarfp.extractfile(member) as fpc:
6769
6874
  shutil.copyfileobj(fpc, fcontents)
6770
6875
  fcontents.seek(0, 0)
@@ -6780,7 +6885,7 @@ def TarFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
6780
6885
  extrasizelen = len(extrasizestr)
6781
6886
  extrasizelenhex = format(extrasizelen, 'x').lower()
6782
6887
  catoutlist = [ftypehex, fname, flinkname, format(int(fsize), 'x').lower(), format(int(fatime), 'x').lower(), format(int(fmtime), 'x').lower(), format(int(fctime), 'x').lower(), format(int(fbtime), 'x').lower(), format(int(fmode), 'x').lower(), format(int(fwinattributes), 'x').lower(), fcompression, format(int(fcsize), 'x').lower(), format(int(fuid), 'x').lower(
6783
- ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+1", extrasizelenhex, format(catfextrafields, 'x').lower()]
6888
+ ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+"+str(len(formatspecs['format_delimiter'])), extrasizelenhex, format(catfextrafields, 'x').lower()]
6784
6889
  catoutlen = len(catoutlist) + len(extradata) + 3
6785
6890
  catoutlenhex = format(catoutlen, 'x').lower()
6786
6891
  catoutlist.insert(0, catoutlenhex)
@@ -6835,7 +6940,7 @@ def TarFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
6835
6940
  if(not contentasfile):
6836
6941
  fcontents = fcontents.read()
6837
6942
  catlist['ffilelist'].append({'fid': fileidnum, 'fidalt': fileidnum, 'fheadersize': int(catheaersize, 16), 'fhstart': catfhstart, 'fhend': catfhend, 'ftype': ftype, 'fname': fname, 'fbasedir': fbasedir, 'flinkname': flinkname, 'fsize': fsize, 'fatime': fatime, 'fmtime': fmtime, 'fctime': fctime, 'fbtime': fbtime, 'fmode': fmode, 'fchmode': fchmode, 'ftypemod': ftypemod, 'fwinattributes': fwinattributes, 'fcompression': fcompression, 'fcsize': fcsize, 'fuid': fuid, 'funame': funame, 'fgid': fgid, 'fgname': fgname, 'finode': finode, 'flinkcount': flinkcount,
6838
- 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+1", 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
6943
+ 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+"+str(len(formatspecs['format_delimiter'])), 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
6839
6944
  fileidnum = fileidnum + 1
6840
6945
  return catlist
6841
6946
 
@@ -7015,7 +7120,7 @@ def ZipFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
7015
7120
  extrasizelen = len(extrasizestr)
7016
7121
  extrasizelenhex = format(extrasizelen, 'x').lower()
7017
7122
  catoutlist = [ftypehex, fname, flinkname, format(int(fsize), 'x').lower(), format(int(fatime), 'x').lower(), format(int(fmtime), 'x').lower(), format(int(fctime), 'x').lower(), format(int(fbtime), 'x').lower(), format(int(fmode), 'x').lower(), format(int(fwinattributes), 'x').lower(), fcompression, format(int(fcsize), 'x').lower(), format(int(fuid), 'x').lower(
7018
- ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+1", extrasizelenhex, format(catfextrafields, 'x').lower()]
7123
+ ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+"+str(len(formatspecs['format_delimiter'])), extrasizelenhex, format(catfextrafields, 'x').lower()]
7019
7124
  catoutlen = len(catoutlist) + len(extradata) + 3
7020
7125
  catoutlenhex = format(catoutlen, 'x').lower()
7021
7126
  catoutlist.insert(0, catoutlenhex)
@@ -7070,7 +7175,7 @@ def ZipFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
7070
7175
  if(not contentasfile):
7071
7176
  fcontents = fcontents.read()
7072
7177
  catlist['ffilelist'].append({'fid': fileidnum, 'fidalt': fileidnum, 'fheadersize': int(catheaersize, 16), 'fhstart': catfhstart, 'fhend': catfhend, 'ftype': ftype, 'fname': fname, 'fbasedir': fbasedir, 'flinkname': flinkname, 'fsize': fsize, 'fatime': fatime, 'fmtime': fmtime, 'fctime': fctime, 'fbtime': fbtime, 'fmode': fmode, 'fchmode': fchmode, 'ftypemod': ftypemod, 'fwinattributes': fwinattributes, 'fcompression': fcompression, 'fcsize': fcsize, 'fuid': fuid, 'funame': funame, 'fgid': fgid, 'fgname': fgname, 'finode': finode, 'flinkcount': flinkcount,
7073
- 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+1", 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
7178
+ 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+"+str(len(formatspecs['format_delimiter'])), 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
7074
7179
  fileidnum = fileidnum + 1
7075
7180
  return catlist
7076
7181
 
@@ -7263,7 +7368,7 @@ if(rarfile_support):
7263
7368
  extrasizelen = len(extrasizestr)
7264
7369
  extrasizelenhex = format(extrasizelen, 'x').lower()
7265
7370
  catoutlist = [ftypehex, fname, flinkname, format(int(fsize), 'x').lower(), format(int(fatime), 'x').lower(), format(int(fmtime), 'x').lower(), format(int(fctime), 'x').lower(), format(int(fbtime), 'x').lower(), format(int(fmode), 'x').lower(), format(int(fwinattributes), 'x').lower(), fcompression, format(int(fcsize), 'x').lower(), format(int(fuid), 'x').lower(
7266
- ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+1", extrasizelenhex, format(catfextrafields, 'x').lower()]
7371
+ ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+"+str(len(formatspecs['format_delimiter'])), extrasizelenhex, format(catfextrafields, 'x').lower()]
7267
7372
  catoutlen = len(catoutlist) + len(extradata) + 3
7268
7373
  catoutlenhex = format(catoutlen, 'x').lower()
7269
7374
  catoutlist.insert(0, catoutlenhex)
@@ -7318,7 +7423,7 @@ if(rarfile_support):
7318
7423
  if(not contentasfile):
7319
7424
  fcontents = fcontents.read()
7320
7425
  catlist['ffilelist'].append({'fid': fileidnum, 'fidalt': fileidnum, 'fheadersize': int(catheaersize, 16), 'fhstart': catfhstart, 'fhend': catfhend, 'ftype': ftype, 'fname': fname, 'fbasedir': fbasedir, 'flinkname': flinkname, 'fsize': fsize, 'fatime': fatime, 'fmtime': fmtime, 'fctime': fctime, 'fbtime': fbtime, 'fmode': fmode, 'fchmode': fchmode, 'ftypemod': ftypemod, 'fwinattributes': fwinattributes, 'fcompression': fcompression, 'fcsize': fcsize, 'fuid': fuid, 'funame': funame, 'fgid': fgid, 'fgname': fgname, 'finode': finode, 'flinkcount': flinkcount,
7321
- 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+1", 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
7426
+ 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+"+str(len(formatspecs['format_delimiter'])), 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
7322
7427
  fileidnum = fileidnum + 1
7323
7428
  return catlist
7324
7429
 
@@ -7455,7 +7560,7 @@ if(py7zr_support):
7455
7560
  extrasizelen = len(extrasizestr)
7456
7561
  extrasizelenhex = format(extrasizelen, 'x').lower()
7457
7562
  catoutlist = [ftypehex, fname, flinkname, format(int(fsize), 'x').lower(), format(int(fatime), 'x').lower(), format(int(fmtime), 'x').lower(), format(int(fctime), 'x').lower(), format(int(fbtime), 'x').lower(), format(int(fmode), 'x').lower(), format(int(fwinattributes), 'x').lower(), fcompression, format(int(fcsize), 'x').lower(), format(int(fuid), 'x').lower(
7458
- ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+1", extrasizelenhex, format(catfextrafields, 'x').lower()]
7563
+ ), funame, format(int(fgid), 'x').lower(), fgname, format(int(fcurfid), 'x').lower(), format(int(fcurinode), 'x').lower(), format(int(flinkcount), 'x').lower(), format(int(fdev), 'x').lower(), format(int(fdev_minor), 'x').lower(), format(int(fdev_major), 'x').lower(), "+"+str(len(formatspecs['format_delimiter'])), extrasizelenhex, format(catfextrafields, 'x').lower()]
7459
7564
  catoutlen = len(catoutlist) + len(extradata) + 3
7460
7565
  catoutlenhex = format(catoutlen, 'x').lower()
7461
7566
  catoutlist.insert(0, catoutlenhex)
@@ -7510,7 +7615,7 @@ if(py7zr_support):
7510
7615
  if(not contentasfile):
7511
7616
  fcontents = fcontents.read()
7512
7617
  catlist['ffilelist'].append({'fid': fileidnum, 'fidalt': fileidnum, 'fheadersize': int(catheaersize, 16), 'fhstart': catfhstart, 'fhend': catfhend, 'ftype': ftype, 'fname': fname, 'fbasedir': fbasedir, 'flinkname': flinkname, 'fsize': fsize, 'fatime': fatime, 'fmtime': fmtime, 'fctime': fctime, 'fbtime': fbtime, 'fmode': fmode, 'fchmode': fchmode, 'ftypemod': ftypemod, 'fwinattributes': fwinattributes, 'fcompression': fcompression, 'fcsize': fcsize, 'fuid': fuid, 'funame': funame, 'fgid': fgid, 'fgname': fgname, 'finode': finode, 'flinkcount': flinkcount,
7513
- 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+1", 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
7618
+ 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': "+"+str(len(formatspecs['format_delimiter'])), 'fheaderchecksumtype': checksumtype, 'fcontentchecksumtype': checksumtype, 'fnumfields': catfnumfields + 2, 'frawheader': catheaderdata, 'fextrafields': catfextrafields, 'fextrafieldsize': extrasizelen, 'fextralist': extrafieldslist, 'fheaderchecksum': int(catfileheadercshex, 16), 'fcontentchecksum': int(catfilecontentcshex, 16), 'fhascontents': pyhascontents, 'fcontentstart': catfcontentstart, 'fcontentend': catfcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents})
7514
7619
  fileidnum = fileidnum + 1
7515
7620
  return catlist
7516
7621
 
@@ -7619,11 +7724,11 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7619
7724
  if(isinstance(infile, dict)):
7620
7725
  listcatfiles = infile
7621
7726
  else:
7622
- if(infile != "-" and not hasattr(infile, "read") and not hasattr(infile, "write")):
7727
+ if(infile != "-" and not isinstance(infile, bytes) and not hasattr(infile, "read") and not hasattr(infile, "write")):
7623
7728
  infile = RemoveWindowsPath(infile)
7624
7729
  listcatfiles = ArchiveFileToArray(
7625
7730
  infile, seekstart, seekend, False, True, skipchecksum, formatspecs, returnfp)
7626
- if(outfile != "-" and not hasattr(infile, "read") and not hasattr(outfile, "write")):
7731
+ if(outfile != "-" and not isinstance(infile, bytes) and not hasattr(infile, "read") and not hasattr(outfile, "write")):
7627
7732
  outfile = RemoveWindowsPath(outfile)
7628
7733
  checksumtype = checksumtype.lower()
7629
7734
  if(not CheckSumSupport(checksumtype, hashlib_guaranteed)):
@@ -7637,7 +7742,7 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7637
7742
  if(verbose):
7638
7743
  logging.basicConfig(format="%(message)s",
7639
7744
  stream=sys.stdout, level=logging.DEBUG)
7640
- if(outfile != "-" and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
7745
+ if(outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write")):
7641
7746
  if(os.path.exists(outfile)):
7642
7747
  try:
7643
7748
  os.unlink(outfile)
@@ -7645,7 +7750,7 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7645
7750
  pass
7646
7751
  if(not listcatfiles):
7647
7752
  return False
7648
- if(outfile == "-"):
7753
+ if(outfile == "-" or outfile is None):
7649
7754
  verbose = False
7650
7755
  catfp = BytesIO()
7651
7756
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
@@ -7840,7 +7945,7 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7840
7945
  if(lcfx > 0):
7841
7946
  catfp.write(AppendNullBytes(
7842
7947
  [0, 0], formatspecs['format_delimiter']).encode("UTF-8"))
7843
- if(outfile == "-" or hasattr(outfile, "read") or hasattr(outfile, "write")):
7948
+ if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
7844
7949
  catfp = CompressArchiveFile(
7845
7950
  catfp, compression, compressionlevel, formatspecs)
7846
7951
  try:
@@ -7859,6 +7964,11 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7859
7964
  shutil.copyfileobj(catfp, sys.stdout.buffer)
7860
7965
  else:
7861
7966
  shutil.copyfileobj(catfp, sys.stdout)
7967
+ elif(outfile is None):
7968
+ catfp.seek(0, 0)
7969
+ outvar = catfp.read()
7970
+ catfp.close()
7971
+ return outvar
7862
7972
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", str(outfile))):
7863
7973
  catfp = CompressArchiveFile(
7864
7974
  catfp, compression, compressionlevel, formatspecs)
@@ -13,7 +13,7 @@
13
13
  Copyright 2016-2024 Game Maker 2k - http://intdb.sourceforge.net/
14
14
  Copyright 2016-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
15
15
 
16
- $FileInfo: setup.py - Last Update: 12/14/2024 Ver. 0.15.8 RC 1 - Author: cooldude2k $
16
+ $FileInfo: setup.py - Last Update: 12/20/2024 Ver. 0.15.12 RC 1 - Author: cooldude2k $
17
17
  '''
18
18
 
19
19
  import os
File without changes
File without changes
File without changes