PyCatFile 0.15.14__tar.gz → 0.15.16__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.14
3
+ Version: 0.15.16
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.14
3
+ Version: 0.15.16
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,5 +1,5 @@
1
1
  #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
2
+ # -*- coding: UTF-8 -*-
3
3
 
4
4
  '''
5
5
  This program is free software; you can redistribute it and/or modify
@@ -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/21/2024 Ver. 0.15.14 RC 1 - Author: cooldude2k $
17
+ $FileInfo: pycatfile.py - Last Update: 12/25/2024 Ver. 0.15.16 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
@@ -94,13 +94,13 @@ except ImportError:
94
94
  # Windows-specific setup
95
95
  if os.name == 'nt':
96
96
  if sys.version_info[0] == 2:
97
- sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
98
- sys.stderr = codecs.getwriter('utf-8')(sys.stderr)
97
+ sys.stdout = codecs.getwriter('UTF-8')(sys.stdout)
98
+ sys.stderr = codecs.getwriter('UTF-8')(sys.stderr)
99
99
  else:
100
100
  sys.stdout = io.TextIOWrapper(
101
- sys.stdout.buffer, encoding='utf-8', errors='replace', line_buffering=True)
101
+ sys.stdout.buffer, encoding='UTF-8', errors='replace', line_buffering=True)
102
102
  sys.stderr = io.TextIOWrapper(
103
- sys.stderr.buffer, encoding='utf-8', errors='replace', line_buffering=True)
103
+ sys.stderr.buffer, encoding='UTF-8', errors='replace', line_buffering=True)
104
104
 
105
105
  hashlib_guaranteed = False
106
106
  # Environment setup
@@ -225,6 +225,16 @@ def get_importing_script_path():
225
225
  return os.path.abspath(filename)
226
226
  return None
227
227
 
228
+ def get_default_threads():
229
+ """Returns the number of CPU threads available, or 1 if unavailable."""
230
+ try:
231
+ cpu_threads = os.cpu_count()
232
+ return cpu_threads if cpu_threads is not None else 1
233
+ except AttributeError:
234
+ # os.cpu_count() might not be available in some environments
235
+ return 1
236
+
237
+
228
238
  __use_pysftp__ = False
229
239
  __use_alt_format__ = False
230
240
  __use_env_file__ = True
@@ -253,7 +263,7 @@ if os.path.exists(__config_file__) and __use_ini_file__:
253
263
  if sys.version_info[0] < 3: # Python 2
254
264
  return value.decode('unicode_escape')
255
265
  else: # Python 3
256
- return bytes(value, 'utf-8').decode('unicode_escape')
266
+ return bytes(value, 'UTF-8').decode('unicode_escape')
257
267
  __file_format_name__ = config.get('main', 'name')
258
268
  __program_name__ = config.get('main', 'proname')
259
269
  __file_format_lower__ = config.get('main', 'lower')
@@ -304,12 +314,12 @@ __file_format_dict__ = {'format_name': __file_format_name__, 'format_magic': __f
304
314
  '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
315
  __project__ = __program_name__
306
316
  __project_url__ = "https://github.com/GameMaker2k/PyCatFile"
307
- __version_info__ = (0, 15, 14, "RC 1", 1)
308
- __version_date_info__ = (2024, 12, 21, "RC 1", 1)
317
+ __version_info__ = (0, 15, 16, "RC 1", 1)
318
+ __version_date_info__ = (2024, 12, 25, "RC 1", 1)
309
319
  __version_date__ = str(__version_date_info__[0]) + "." + str(
310
320
  __version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
311
321
  __revision__ = __version_info__[3]
312
- __revision_id__ = "$Id: 5ac437d67d0b485df434560f6f73d2823777d4c1 $"
322
+ __revision_id__ = "$Id: e3bae7488c237d5480aaf274033b0730fad054fc $"
313
323
  if(__version_info__[4] is not None):
314
324
  __version_date_plusrc__ = __version_date__ + \
315
325
  "-" + str(__version_date_info__[4])
@@ -340,14 +350,14 @@ geturls_ua_pycatfile_python_alt = "Mozilla/5.0 ({osver}; {archtype}; +{prourl})
340
350
  )+" "+platform.release(), archtype=platform.machine(), prourl=__project_url__, pyimp=py_implementation, pyver=platform.python_version(), proname=__project__, prover=__version__)
341
351
  geturls_ua_googlebot_google = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
342
352
  geturls_ua_googlebot_google_old = "Googlebot/2.1 (+http://www.google.com/bot.html)"
343
- geturls_headers_pycatfile_python = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_pycatfile_python, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close",
353
+ geturls_headers_pycatfile_python = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_pycatfile_python, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,UTF-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close",
344
354
  'SEC-CH-UA': "\""+__project__+"\";v=\""+str(__version__)+"\", \"Not;A=Brand\";v=\"8\", \""+py_implementation+"\";v=\""+str(platform.release())+"\"", 'SEC-CH-UA-FULL-VERSION': str(__version__), 'SEC-CH-UA-PLATFORM': ""+py_implementation+"", 'SEC-CH-UA-ARCH': ""+platform.machine()+"", 'SEC-CH-UA-PLATFORM': str(__version__), 'SEC-CH-UA-BITNESS': str(PyBitness)}
345
- geturls_headers_pycatfile_python_alt = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_pycatfile_python_alt, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close",
355
+ geturls_headers_pycatfile_python_alt = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_pycatfile_python_alt, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,UTF-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close",
346
356
  'SEC-CH-UA': "\""+__project__+"\";v=\""+str(__version__)+"\", \"Not;A=Brand\";v=\"8\", \""+py_implementation+"\";v=\""+str(platform.release())+"\"", 'SEC-CH-UA-FULL-VERSION': str(__version__), 'SEC-CH-UA-PLATFORM': ""+py_implementation+"", 'SEC-CH-UA-ARCH': ""+platform.machine()+"", 'SEC-CH-UA-PLATFORM': str(__version__), 'SEC-CH-UA-BITNESS': str(PyBitness)}
347
357
  geturls_headers_googlebot_google = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_googlebot_google, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
348
- 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
358
+ 'Accept-Charset': "ISO-8859-1,ISO-8859-15,UTF-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
349
359
  geturls_headers_googlebot_google_old = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_googlebot_google_old, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
350
- 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
360
+ 'Accept-Charset': "ISO-8859-1,ISO-8859-15,UTF-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
351
361
 
352
362
  compressionsupport = []
353
363
  try:
@@ -598,7 +608,7 @@ def ListDir(dirpath, followlink=False, duplicates=False, include_regex=None, exc
598
608
  elif isinstance(dirpath, basestring):
599
609
  dirpath = list(filter(None, [dirpath]))
600
610
  retlist = []
601
- fs_encoding = sys.getfilesystemencoding() or 'utf-8'
611
+ fs_encoding = sys.getfilesystemencoding() or 'UTF-8'
602
612
  include_pattern = re.compile(include_regex) if include_regex else None
603
613
  exclude_pattern = re.compile(exclude_regex) if exclude_regex else None
604
614
  for mydirfile in dirpath:
@@ -665,7 +675,7 @@ def ListDirAdvanced(dirpath, followlink=False, duplicates=False, include_regex=N
665
675
  elif isinstance(dirpath, basestring):
666
676
  dirpath = list(filter(None, [dirpath]))
667
677
  retlist = []
668
- fs_encoding = sys.getfilesystemencoding() or 'utf-8'
678
+ fs_encoding = sys.getfilesystemencoding() or 'UTF-8'
669
679
  include_pattern = re.compile(include_regex) if include_regex else None
670
680
  exclude_pattern = re.compile(exclude_regex) if exclude_regex else None
671
681
  for mydirfile in dirpath:
@@ -813,11 +823,11 @@ class ZlibFile:
813
823
  self._compressed_data, self.wbits)
814
824
  if self._text_mode:
815
825
  self._decompressed_data = self._decompressed_data.decode(
816
- self.encoding or 'utf-8', self.errors or 'strict')
826
+ self.encoding or 'UTF-8', self.errors or 'strict')
817
827
 
818
828
  def write(self, data):
819
829
  if self._text_mode:
820
- data = data.encode(self.encoding or 'utf-8',
830
+ data = data.encode(self.encoding or 'UTF-8',
821
831
  self.errors or 'strict')
822
832
  compressed_data = self._compressor.compress(
823
833
  data) + self._compressor.flush(zlib.Z_SYNC_FLUSH)
@@ -928,11 +938,11 @@ class GzipFile:
928
938
  self._decompressed_data = gzip.decompress(self._compressed_data)
929
939
  if self._text_mode:
930
940
  self._decompressed_data = self._decompressed_data.decode(
931
- self.encoding or 'utf-8', self.errors or 'strict')
941
+ self.encoding or 'UTF-8', self.errors or 'strict')
932
942
 
933
943
  def write(self, data):
934
944
  if self._text_mode:
935
- data = data.encode(self.encoding or 'utf-8',
945
+ data = data.encode(self.encoding or 'UTF-8',
936
946
  self.errors or 'strict')
937
947
  compressed_data = self._compressor.compress(data)
938
948
  self.file.write(compressed_data)
@@ -1039,11 +1049,11 @@ class BloscFile:
1039
1049
  raise ValueError("Invalid blosc file header");
1040
1050
  self._decompressed_data = blosc.decompress(self._compressed_data);
1041
1051
  if self._text_mode:
1042
- self._decompressed_data = self._decompressed_data.decode(self.encoding or 'utf-8', self.errors or 'strict');
1052
+ self._decompressed_data = self._decompressed_data.decode(self.encoding or 'UTF-8', self.errors or 'strict');
1043
1053
 
1044
1054
  def write(self, data):
1045
1055
  if self._text_mode:
1046
- data = data.encode(self.encoding or 'utf-8', self.errors or 'strict');
1056
+ data = data.encode(self.encoding or 'UTF-8', self.errors or 'strict');
1047
1057
  compressed_data = blosc.compress(data, cname='blosclz', clevel=self.level);
1048
1058
  self.file.write(compressed_data);
1049
1059
  self.file.flush();
@@ -1146,11 +1156,11 @@ class BrotliFile:
1146
1156
  raise ValueError("Invalid brotli file header");
1147
1157
  self._decompressed_data = brotli.decompress(self._compressed_data);
1148
1158
  if self._text_mode:
1149
- self._decompressed_data = self._decompressed_data.decode(self.encoding or 'utf-8', self.errors or 'strict');
1159
+ self._decompressed_data = self._decompressed_data.decode(self.encoding or 'UTF-8', self.errors or 'strict');
1150
1160
 
1151
1161
  def write(self, data):
1152
1162
  if self._text_mode:
1153
- data = data.encode(self.encoding or 'utf-8', self.errors or 'strict');
1163
+ data = data.encode(self.encoding or 'UTF-8', self.errors or 'strict');
1154
1164
  compressed_data = self._compressor.process(data);
1155
1165
  self.file.write(compressed_data);
1156
1166
  self.file.flush();
@@ -1785,7 +1795,7 @@ def ReadFileHeaderDataBySizeWithContent(fp, listonly=False, uncompress=True, ski
1785
1795
  else:
1786
1796
  fcontents.seek(0, 0)
1787
1797
  if(uncompress):
1788
- fcontents = UncompressArchiveFile(fcontents, formatspecs)
1798
+ fcontents = UncompressBytesAltFPFP(fcontents, formatspecs)
1789
1799
  fcontentend = fp.tell()
1790
1800
  if(re.findall("^\\+([0-9]+)", fseeknextfile)):
1791
1801
  fseeknextasnum = int(fseeknextfile.replace("+", ""))
@@ -1898,7 +1908,7 @@ def ReadFileHeaderDataBySizeWithContentToArray(fp, listonly=False, contentasfile
1898
1908
  else:
1899
1909
  fcontents.seek(0, 0)
1900
1910
  if(uncompress):
1901
- fcontents = UncompressArchiveFile(fcontents, formatspecs)
1911
+ fcontents = UncompressBytesAltFP(fcontents, formatspecs)
1902
1912
  fcontents.seek(0, 0)
1903
1913
  fccs = GetFileChecksum(
1904
1914
  fcontents.read(), HeaderOut[-3].lower(), False, formatspecs)
@@ -2020,7 +2030,7 @@ def ReadFileHeaderDataBySizeWithContentToList(fp, listonly=False, uncompress=Tru
2020
2030
  else:
2021
2031
  fcontents.seek(0, 0)
2022
2032
  if(uncompress):
2023
- fcontents = UncompressArchiveFile(fcontents, formatspecs)
2033
+ fcontents = UncompressBytesAltFP(fcontents, formatspecs)
2024
2034
  fcontents.seek(0, 0)
2025
2035
  fcontentend = fp.tell() - 1
2026
2036
  if(re.findall("^\\+([0-9]+)", fseeknextfile)):
@@ -2296,7 +2306,7 @@ def ReadInFileBySizeWithContentToArray(infile, seekstart=0, seekend=0, listonly=
2296
2306
  if(hasattr(infile, "read") or hasattr(infile, "write")):
2297
2307
  fp = infile
2298
2308
  fp.seek(0, 0)
2299
- fp = UncompressArchiveFile(fp, formatspecs)
2309
+ fp = UncompressBytesAltFP(fp, formatspecs)
2300
2310
  checkcompressfile = CheckCompressionSubType(fp, formatspecs, True)
2301
2311
  if(checkcompressfile != "catfile" and checkcompressfile != formatspecs['format_lower']):
2302
2312
  return False
@@ -2310,13 +2320,13 @@ def ReadInFileBySizeWithContentToArray(infile, seekstart=0, seekend=0, listonly=
2310
2320
  else:
2311
2321
  shutil.copyfileobj(sys.stdin, fp)
2312
2322
  fp.seek(0, 0)
2313
- fp = UncompressArchiveFile(fp, formatspecs)
2323
+ fp = UncompressBytesAltFP(fp, formatspecs)
2314
2324
  if(not fp):
2315
2325
  return False
2316
2326
  fp.seek(0, 0)
2317
2327
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
2318
2328
  fp = download_file_from_internet_file(infile)
2319
- fp = UncompressArchiveFile(fp, formatspecs)
2329
+ fp = UncompressBytesAltFP(fp, formatspecs)
2320
2330
  fp.seek(0, 0)
2321
2331
  if(not fp):
2322
2332
  return False
@@ -2359,7 +2369,7 @@ def ReadInFileBySizeWithContentToList(infile, seekstart=0, seekend=0, listonly=F
2359
2369
  if(hasattr(infile, "read") or hasattr(infile, "write")):
2360
2370
  fp = infile
2361
2371
  fp.seek(0, 0)
2362
- fp = UncompressArchiveFile(fp, formatspecs)
2372
+ fp = UncompressBytesAltFP(fp, formatspecs)
2363
2373
  checkcompressfile = CheckCompressionSubType(fp, formatspecs, True)
2364
2374
  if(checkcompressfile != "catfile" and checkcompressfile != formatspecs['format_lower']):
2365
2375
  return False
@@ -2373,13 +2383,13 @@ def ReadInFileBySizeWithContentToList(infile, seekstart=0, seekend=0, listonly=F
2373
2383
  else:
2374
2384
  shutil.copyfileobj(sys.stdin, fp)
2375
2385
  fp.seek(0, 0)
2376
- fp = UncompressArchiveFile(fp, formatspecs)
2386
+ fp = UncompressBytesAltFP(fp, formatspecs)
2377
2387
  if(not fp):
2378
2388
  return False
2379
2389
  fp.seek(0, 0)
2380
2390
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
2381
2391
  fp = download_file_from_internet_file(infile)
2382
- fp = UncompressArchiveFile(fp, formatspecs)
2392
+ fp = UncompressBytesAltFP(fp, formatspecs)
2383
2393
  fp.seek(0, 0)
2384
2394
  if(not fp):
2385
2395
  return False
@@ -2785,6 +2795,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2785
2795
  ilcsize = []
2786
2796
  while(ilmin < ilsize):
2787
2797
  cfcontents = BytesIO()
2798
+ fcontents.seek(0, 0)
2788
2799
  shutil.copyfileobj(fcontents, cfcontents)
2789
2800
  fcontents.seek(0, 0)
2790
2801
  cfcontents.seek(0, 0)
@@ -2801,18 +2812,18 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2801
2812
  ilcsize.append(sys.maxsize)
2802
2813
  ilmin = ilmin + 1
2803
2814
  ilcmin = ilcsize.index(min(ilcsize))
2804
- compression = compressionlistalt[ilcmin]
2815
+ curcompression = compressionlistalt[ilcmin]
2805
2816
  fcontents.seek(0, 0)
2806
2817
  cfcontents = BytesIO()
2807
2818
  shutil.copyfileobj(fcontents, cfcontents)
2808
2819
  cfcontents.seek(0, 0)
2809
2820
  cfcontents = CompressArchiveFile(
2810
- cfcontents, compression, compressionlevel, formatspecs)
2821
+ cfcontents, curcompression, compressionlevel, formatspecs)
2811
2822
  cfcontents.seek(0, 2)
2812
2823
  cfsize = cfcontents.tell()
2813
2824
  if(ucfsize > cfsize):
2814
2825
  fcsize = format(int(cfsize), 'x').lower()
2815
- fcompression = compression
2826
+ fcompression = curcompression
2816
2827
  fcontents.close()
2817
2828
  fcontents = cfcontents
2818
2829
  if(followlink and (ftype == 1 or ftype == 2)):
@@ -2829,6 +2840,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2829
2840
  ilcsize = []
2830
2841
  while(ilmin < ilsize):
2831
2842
  cfcontents = BytesIO()
2843
+ fcontents.seek(0, 0)
2832
2844
  shutil.copyfileobj(fcontents, cfcontents)
2833
2845
  fcontents.seek(0, 0)
2834
2846
  cfcontents.seek(0, 0)
@@ -2845,18 +2857,18 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
2845
2857
  ilcsize.append(sys.maxsize)
2846
2858
  ilmin = ilmin + 1
2847
2859
  ilcmin = ilcsize.index(min(ilcsize))
2848
- compression = compressionlistalt[ilcmin]
2860
+ curcompression = compressionlistalt[ilcmin]
2849
2861
  fcontents.seek(0, 0)
2850
2862
  cfcontents = BytesIO()
2851
2863
  shutil.copyfileobj(fcontents, cfcontents)
2852
2864
  cfcontents.seek(0, 0)
2853
2865
  cfcontents = CompressArchiveFile(
2854
- cfcontents, compression, compressionlevel, formatspecs)
2866
+ cfcontents, curcompression, compressionlevel, formatspecs)
2855
2867
  cfcontents.seek(0, 2)
2856
2868
  cfsize = cfcontents.tell()
2857
2869
  if(ucfsize > cfsize):
2858
2870
  fcsize = format(int(cfsize), 'x').lower()
2859
- fcompression = compression
2871
+ fcompression = curcompression
2860
2872
  fcontents.close()
2861
2873
  fcontents = cfcontents
2862
2874
  if(fcompression == "none"):
@@ -3273,6 +3285,16 @@ def CheckCompressionTypeFromString(instring, formatspecs=__file_format_dict__, c
3273
3285
  return CheckCompressionType(instringsfile, formatspecs, closefp)
3274
3286
 
3275
3287
 
3288
+ def CheckCompressionTypeFromBytes(instring, formatspecs=__file_format_dict__, closefp=True):
3289
+ formatspecs = FormatSpecsListToDict(formatspecs)
3290
+ try:
3291
+ instringsfile = BytesIO(instring)
3292
+ except TypeError:
3293
+ instringsfile = BytesIO(instring.decode("UTF-8"))
3294
+ return CheckCompressionType(instringsfile, formatspecs, closefp)
3295
+
3296
+
3297
+
3276
3298
  def GetCompressionMimeType(infile, formatspecs=__file_format_dict__):
3277
3299
  formatspecs = FormatSpecsListToDict(formatspecs)
3278
3300
  compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -3309,7 +3331,7 @@ def UncompressArchiveFile(fp, formatspecs=__file_format_dict__):
3309
3331
  elif(compresscheck == "bzip2" and compresscheck in compressionsupport):
3310
3332
  catfp = bz2.BZ2File(fp)
3311
3333
  elif(compresscheck == "zstd" and compresscheck in compressionsupport):
3312
- catfp = zstd.ZstdDecompressor().stream_reader(fp)
3334
+ catfp = zstandard.ZstdDecompressor().stream_reader(fp)
3313
3335
  elif(compresscheck == "lz4" and compresscheck in compressionsupport):
3314
3336
  catfp = lz4.frame.LZ4FrameFile(fp, mode='rb')
3315
3337
  elif((compresscheck == "lzo" or compresscheck == "lzop") and compresscheck in compressionsupport):
@@ -3347,47 +3369,24 @@ def UncompressFile(infile, formatspecs=__file_format_dict__, mode="rb"):
3347
3369
  mode = "w"
3348
3370
  try:
3349
3371
  if(compresscheck == "gzip" and compresscheck in compressionsupport):
3350
- try:
3351
- filefp = gzip.open(infile, mode, encoding="UTF-8")
3352
- except (ValueError, TypeError) as e:
3353
- filefp = gzip.open(infile, mode)
3372
+ filefp = gzip.open(infile, mode)
3354
3373
  if(compresscheck == "bzip2" and compresscheck in compressionsupport):
3355
- try:
3356
- filefp = bz2.open(infile, mode, encoding="UTF-8")
3357
- except (ValueError, TypeError) as e:
3358
- filefp = bz2.open(infile, mode)
3374
+ filefp = bz2.open(infile, mode)
3359
3375
  if(compresscheck == "zstd" and compresscheck in compressionsupport):
3360
- try:
3361
- filefp = zstandard.open(infile, mode, encoding="UTF-8")
3362
- except (ValueError, TypeError) as e:
3363
- filefp = zstandard.open(infile, mode)
3376
+ decompressor = zstandard.ZstdDecompressor()
3377
+ filefp = decompressor.open(infile, mode)
3364
3378
  if(compresscheck == "lz4" and compresscheck in compressionsupport):
3365
- try:
3366
- filefp = lz4.frame.open(infile, mode, encoding="UTF-8")
3367
- except (ValueError, TypeError) as e:
3368
- filefp = lz4.frame.open(infile, mode)
3379
+ filefp = lz4.frame.open(infile, mode)
3369
3380
  if((compresscheck == "lzo" or compresscheck == "lzop") and compresscheck in compressionsupport):
3370
- try:
3371
- filefp = lzo.open(infile, mode, encoding="UTF-8")
3372
- except (ValueError, TypeError) as e:
3373
- filefp = lzo.open(infile, mode)
3381
+ filefp = lzo.open(infile, mode)
3374
3382
  if((compresscheck == "lzma" or compresscheck == "xz") and compresscheck in compressionsupport):
3375
- try:
3376
- filefp = lzma.open(infile, mode, encoding="UTF-8")
3377
- except (ValueError, TypeError) as e:
3378
- filefp = lzma.open(infile, mode)
3383
+ filefp = lzma.open(infile, mode)
3379
3384
  if(compresscheck == "zlib" and compresscheck in compressionsupport):
3380
3385
  filefp = ZlibFile(infile, mode=mode)
3381
3386
  if(compresscheck == "catfile" or compresscheck == formatspecs['format_lower']):
3382
- try:
3383
- filefp = open(infile, mode, encoding="UTF-8")
3384
- except (ValueError, TypeError) as e:
3385
- filefp = open(infile, mode)
3387
+ filefp = open(infile, mode)
3386
3388
  if(not compresscheck):
3387
- try:
3388
- filefp = open(infile, mode, encoding="UTF-8")
3389
- except (ValueError, TypeError) as e:
3390
- filefp = open(infile, mode)
3389
+ filefp = open(infile, mode)
3391
3390
  except FileNotFoundError:
3392
3391
  return False
3393
3392
  try:
@@ -3397,18 +3396,15 @@ def UncompressFile(infile, formatspecs=__file_format_dict__, mode="rb"):
3397
3396
  return filefp
3398
3397
 
3399
3398
 
3400
- def UncompressString(infile):
3399
+ def UncompressString(infile, formatspecs=__file_format_dict__):
3401
3400
  compresscheck = CheckCompressionTypeFromString(infile, formatspecs, False)
3402
3401
  if(compresscheck == "gzip" and compresscheck in compressionsupport):
3403
3402
  fileuz = GzipDecompressData(infile)
3404
3403
  if(compresscheck == "bzip2" and compresscheck in compressionsupport):
3405
3404
  fileuz = BzipDecompressData(infile)
3406
3405
  if(compresscheck == "zstd" and compresscheck in compressionsupport):
3407
- try:
3408
- import zstandard
3409
- except ImportError:
3410
- return False
3411
- fileuz = zstandard.decompress(infile)
3406
+ decompressor = zstandard.ZstdDecompressor()
3407
+ fileuz = decompressor.decompress(infile)
3412
3408
  if(compresscheck == "lz4" and compresscheck in compressionsupport):
3413
3409
  fileuz = lz4.frame.decompress(infile)
3414
3410
  if((compresscheck == "lzo" or compresscheck == "lzop") and compresscheck in compressionsupport):
@@ -3424,9 +3420,68 @@ def UncompressString(infile):
3424
3420
  return fileuz
3425
3421
 
3426
3422
 
3427
- def UncompressStringAlt(infile):
3423
+ def UncompressStringAlt(instring, formatspecs=__file_format_dict__):
3424
+ filefp = StringIO()
3425
+ outstring = UncompressString(instring, formatspecs)
3426
+ filefp.write(outstring)
3427
+ filefp.seek(0, 0)
3428
+ return filefp
3429
+
3430
+ def UncompressStringAltFP(fp, formatspecs=__file_format_dict__):
3431
+ if(not hasattr(fp, "read")):
3432
+ return False
3433
+ prechck = CheckCompressionType(fp, formatspecs, False)
3434
+ fp.seek(0, 0)
3435
+ if(prechck!="zstd"):
3436
+ return UncompressArchiveFile(fp, formatspecs)
3428
3437
  filefp = StringIO()
3429
- outstring = UncompressString(infile)
3438
+ fp.seek(0, 0)
3439
+ outstring = UncompressString(fp.read(), formatspecs)
3440
+ filefp.write(outstring)
3441
+ filefp.seek(0, 0)
3442
+ return filefp
3443
+
3444
+
3445
+ def UncompressBytes(infile, formatspecs=__file_format_dict__):
3446
+ compresscheck = CheckCompressionTypeFromBytes(infile, formatspecs, False)
3447
+ if(compresscheck == "gzip" and compresscheck in compressionsupport):
3448
+ fileuz = GzipDecompressData(infile)
3449
+ if(compresscheck == "bzip2" and compresscheck in compressionsupport):
3450
+ fileuz = BzipDecompressData(infile)
3451
+ if(compresscheck == "zstd" and compresscheck in compressionsupport):
3452
+ decompressor = zstandard.ZstdDecompressor()
3453
+ fileuz = decompressor.decompress(infile)
3454
+ if(compresscheck == "lz4" and compresscheck in compressionsupport):
3455
+ fileuz = lz4.frame.decompress(infile)
3456
+ if((compresscheck == "lzo" or compresscheck == "lzop") and compresscheck in compressionsupport):
3457
+ fileuz = lzo.decompress(infile)
3458
+ if((compresscheck == "lzma" or compresscheck == "xz") and compresscheck in compressionsupport):
3459
+ fileuz = lzma.decompress(infile)
3460
+ if(compresscheck == "zlib" and compresscheck in compressionsupport):
3461
+ fileuz = zlib.decompress(infile)
3462
+ if(not compresscheck):
3463
+ fileuz = infile
3464
+ return fileuz
3465
+
3466
+
3467
+ def UncompressBytesAlt(inbytes, formatspecs=__file_format_dict__):
3468
+ filefp = BytesIO()
3469
+ outstring = UncompressBytes(inbytes, formatspecs)
3470
+ filefp.write(outstring)
3471
+ filefp.seek(0, 0)
3472
+ return filefp
3473
+
3474
+
3475
+ def UncompressBytesAltFP(fp, formatspecs=__file_format_dict__):
3476
+ if(not hasattr(fp, "read")):
3477
+ return False
3478
+ prechck = CheckCompressionType(fp, formatspecs, False)
3479
+ fp.seek(0, 0)
3480
+ if(prechck!="zstd"):
3481
+ return UncompressArchiveFile(fp, formatspecs)
3482
+ filefp = BytesIO()
3483
+ fp.seek(0, 0)
3484
+ outstring = UncompressBytes(fp.read(), formatspecs)
3430
3485
  filefp.write(outstring)
3431
3486
  filefp.seek(0, 0)
3432
3487
  return filefp
@@ -3483,7 +3538,7 @@ def CheckCompressionSubType(infile, formatspecs=__file_format_dict__, closefp=Tr
3483
3538
  if(py7zr_support and compresscheck == "7zipfile" and py7zr.is_7zfile(infile)):
3484
3539
  return "7zipfile"
3485
3540
  if(hasattr(infile, "read") or hasattr(infile, "write")):
3486
- catfp = UncompressArchiveFile(infile, formatspecs['format_lower'])
3541
+ catfp = UncompressBytesAltFP(infile, formatspecs['format_lower'])
3487
3542
  else:
3488
3543
  try:
3489
3544
  if(compresscheck == "gzip" and compresscheck in compressionsupport):
@@ -3569,26 +3624,31 @@ def CompressArchiveFile(fp, compression="auto", compressionlevel=None, formatspe
3569
3624
  if(compression == "zstd" and compression in compressionsupport):
3570
3625
  catfp = BytesIO()
3571
3626
  if(compressionlevel is None):
3572
- compressionlevel = 10
3627
+ compressionlevel = 9
3573
3628
  else:
3574
3629
  compressionlevel = int(compressionlevel)
3575
- catfp.write(zstandard.compress(fp.read(), level=compressionlevel))
3630
+ compressor = zstandard.ZstdCompressor(compressionlevel, threads=get_default_threads())
3631
+ catfp.write(compressor.compress(fp.read()))
3576
3632
  if(compression == "lzma" and compression in compressionsupport):
3577
3633
  catfp = BytesIO()
3578
3634
  if(compressionlevel is None):
3579
3635
  compressionlevel = 9
3580
3636
  else:
3581
3637
  compressionlevel = int(compressionlevel)
3582
- catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_ALONE, filters=[
3583
- {"id": lzma.FILTER_LZMA1, "preset": compressionlevel}]))
3638
+ try:
3639
+ catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_ALONE, filters=[{"id": lzma.FILTER_LZMA1, "preset": compressionlevel}]))
3640
+ except (NotImplementedError, lzma.LZMAError):
3641
+ catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_ALONE))
3584
3642
  if(compression == "xz" and compression in compressionsupport):
3585
3643
  catfp = BytesIO()
3586
3644
  if(compressionlevel is None):
3587
3645
  compressionlevel = 9
3588
3646
  else:
3589
3647
  compressionlevel = int(compressionlevel)
3590
- catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_XZ, filters=[
3591
- {"id": lzma.FILTER_LZMA2, "preset": compressionlevel}]))
3648
+ try:
3649
+ catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_XZ, filters=[{"id": lzma.FILTER_LZMA2, "preset": compressionlevel}]))
3650
+ except (NotImplementedError, lzma.LZMAError):
3651
+ catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_XZ))
3592
3652
  if(compression == "zlib" and compression in compressionsupport):
3593
3653
  catfp = BytesIO()
3594
3654
  if(compressionlevel is None):
@@ -3611,10 +3671,8 @@ def CompressOpenFile(outfile, compressionenable=True, compressionlevel=None):
3611
3671
  return False
3612
3672
  fbasename = os.path.splitext(outfile)[0]
3613
3673
  fextname = os.path.splitext(outfile)[1]
3614
- if(compressionlevel is None and fextname != ".zst"):
3674
+ if(compressionlevel is None):
3615
3675
  compressionlevel = 9
3616
- elif(compressionlevel is None and fextname == ".zst"):
3617
- compressionlevel = 10
3618
3676
  else:
3619
3677
  compressionlevel = int(compressionlevel)
3620
3678
  if(sys.version_info[0] == 2):
@@ -3623,56 +3681,29 @@ def CompressOpenFile(outfile, compressionenable=True, compressionlevel=None):
3623
3681
  mode = "wb"
3624
3682
  try:
3625
3683
  if(fextname not in outextlistwd or not compressionenable):
3626
- try:
3627
- outfp = open(outfile, "wb", encoding="UTF-8")
3628
- except (ValueError, TypeError) as e:
3629
- outfp = open(outfile, "wb")
3684
+ outfp = open(outfile, "wb")
3630
3685
  elif(fextname == ".gz" and "gzip" in compressionsupport):
3631
- try:
3632
- outfp = gzip.open(
3633
- outfile, mode, compressionlevel, encoding="UTF-8")
3634
- except (ValueError, TypeError) as e:
3635
- outfp = gzip.open(outfile, mode, compressionlevel)
3686
+ outfp = gzip.open(outfile, mode, compressionlevel)
3636
3687
  elif(fextname == ".bz2" and "bzip2" in compressionsupport):
3637
- try:
3638
- outfp = bz2.open(
3639
- outfile, mode, compressionlevel, encoding="UTF-8")
3640
- except (ValueError, TypeError) as e:
3641
- outfp = bz2.open(outfile, mode, compressionlevel)
3688
+ outfp = bz2.open(outfile, mode, compressionlevel)
3642
3689
  elif(fextname == ".zst" and "zstandard" in compressionsupport):
3643
- try:
3644
- outfp = zstandard.open(outfile, mode, zstandard.ZstdCompressor(
3645
- level=compressionlevel), encoding="UTF-8")
3646
- except (ValueError, TypeError) as e:
3647
- outfp = zstandard.open(
3648
- outfile, mode, zstandard.ZstdCompressor(level=compressionlevel))
3690
+ outfp = zstandard.open(
3691
+ outfile, mode, zstandard.ZstdCompressor(level=compressionlevel, threads=get_default_threads()))
3649
3692
  elif(fextname == ".xz" and "xz" in compressionsupport):
3650
3693
  try:
3651
- outfp = lzma.open(outfile, mode, format=lzma.FORMAT_XZ, filters=[
3652
- {"id": lzma.FILTER_LZMA2, "preset": compressionlevel}], encoding="UTF-8")
3653
- except (ValueError, TypeError) as e:
3654
- outfp = lzma.open(outfile, mode, format=lzma.FORMAT_XZ, filters=[
3655
- {"id": lzma.FILTER_LZMA2, "preset": compressionlevel}])
3694
+ outfp = lzma.open(outfile, mode, format=lzma.FORMAT_XZ, filters=[{"id": lzma.FILTER_LZMA2, "preset": compressionlevel}])
3695
+ except (NotImplementedError, lzma.LZMAError):
3696
+ outfp = lzma.open(outfile, mode, format=lzma.FORMAT_XZ)
3656
3697
  elif(fextname == ".lz4" and "lz4" in compressionsupport):
3657
- try:
3658
- outfp = lz4.frame.open(
3659
- outfile, mode, compression_level=compressionlevel, encoding="UTF-8")
3660
- except (ValueError, TypeError) as e:
3661
- outfp = lz4.frame.open(
3698
+ outfp = lz4.frame.open(
3662
3699
  outfile, mode, compression_level=compressionlevel)
3663
3700
  elif(fextname == ".lzo" and "lzop" in compressionsupport):
3664
- try:
3665
- outfp = lzo.open(
3666
- outfile, mode, compresslevel=compressionlevel, encoding="UTF-8")
3667
- except (ValueError, TypeError) as e:
3668
- outfp = lzo.open(outfile, mode, compresslevel=compressionlevel)
3701
+ outfp = lzo.open(outfile, mode, compresslevel=compressionlevel)
3669
3702
  elif(fextname == ".lzma" and "lzma" in compressionsupport):
3670
3703
  try:
3671
- outfp = lzma.open(outfile, mode, format=lzma.FORMAT_ALONE, filters=[
3672
- {"id": lzma.FILTER_LZMA1, "preset": compressionlevel}], encoding="UTF-8")
3673
- except (ValueError, TypeError) as e:
3674
- outfp = lzma.open(outfile, mode, format=lzma.FORMAT_ALONE, filters=[
3675
- {"id": lzma.FILTER_LZMA1, "preset": compressionlevel}])
3704
+ outfp = lzma.open(outfile, mode, format=lzma.FORMAT_ALONE, filters=[{"id": lzma.FILTER_LZMA1, "preset": compressionlevel}])
3705
+ except (NotImplementedError, lzma.LZMAError):
3706
+ outfp = lzma.open(outfile, mode, format=lzma.FORMAT_ALONE)
3676
3707
  elif((fextname == ".zz" or fextname == ".zl" or fextname == ".zlib") and "zlib" in compressionsupport):
3677
3708
  outfp = ZlibFile(outfile, mode=mode, level=compressionlevel)
3678
3709
  except FileNotFoundError:
@@ -3970,6 +4001,7 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3970
4001
  ilcsize = []
3971
4002
  while(ilmin < ilsize):
3972
4003
  cfcontents = BytesIO()
4004
+ fcontents.seek(0, 0)
3973
4005
  shutil.copyfileobj(fcontents, cfcontents)
3974
4006
  fcontents.seek(0, 0)
3975
4007
  cfcontents.seek(0, 0)
@@ -3986,18 +4018,18 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
3986
4018
  ilcsize.append(sys.maxsize)
3987
4019
  ilmin = ilmin + 1
3988
4020
  ilcmin = ilcsize.index(min(ilcsize))
3989
- compression = compressionlistalt[ilcmin]
4021
+ curcompression = compressionlistalt[ilcmin]
3990
4022
  fcontents.seek(0, 0)
3991
4023
  cfcontents = BytesIO()
3992
4024
  shutil.copyfileobj(fcontents, cfcontents)
3993
4025
  cfcontents.seek(0, 0)
3994
4026
  cfcontents = CompressArchiveFile(
3995
- cfcontents, compression, compressionlevel, formatspecs)
4027
+ cfcontents, curcompression, compressionlevel, formatspecs)
3996
4028
  cfcontents.seek(0, 2)
3997
4029
  cfsize = cfcontents.tell()
3998
4030
  if(ucfsize > cfsize):
3999
4031
  fcsize = format(int(cfsize), 'x').lower()
4000
- fcompression = compression
4032
+ fcompression = curcompression
4001
4033
  fcontents.close()
4002
4034
  fcontents = cfcontents
4003
4035
  if(fcompression == "none"):
@@ -4016,6 +4048,7 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
4016
4048
  ilcsize = []
4017
4049
  while(ilmin < ilsize):
4018
4050
  cfcontents = BytesIO()
4051
+ fcontents.seek(0, 0)
4019
4052
  shutil.copyfileobj(fcontents, cfcontents)
4020
4053
  fcontents.seek(0, 0)
4021
4054
  cfcontents.seek(0, 0)
@@ -4032,18 +4065,18 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, compression="auto",
4032
4065
  ilcsize.append(sys.maxsize)
4033
4066
  ilmin = ilmin + 1
4034
4067
  ilcmin = ilcsize.index(min(ilcsize))
4035
- compression = compressionlistalt[ilcmin]
4068
+ curcompression = compressionlistalt[ilcmin]
4036
4069
  fcontents.seek(0, 0)
4037
4070
  cfcontents = BytesIO()
4038
4071
  shutil.copyfileobj(fcontents, cfcontents)
4039
4072
  cfcontents.seek(0, 0)
4040
4073
  cfcontents = CompressArchiveFile(
4041
- cfcontents, compression, compressionlevel, formatspecs)
4074
+ cfcontents, curcompression, compressionlevel, formatspecs)
4042
4075
  cfcontents.seek(0, 2)
4043
4076
  cfsize = cfcontents.tell()
4044
4077
  if(ucfsize > cfsize):
4045
4078
  fcsize = format(int(cfsize), 'x').lower()
4046
- fcompression = compression
4079
+ fcompression = curcompression
4047
4080
  fcontents.close()
4048
4081
  fcontents = cfcontents
4049
4082
  fcontents.seek(0, 0)
@@ -4268,48 +4301,49 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4268
4301
  fcsize = format(int(0), 'x').lower()
4269
4302
  fcontents = BytesIO()
4270
4303
  if ftype in data_types:
4271
- with tarfp.extractfile(member) as fpc:
4272
- shutil.copyfileobj(fpc, fcontents)
4273
- if(not compresswholefile):
4274
- fcontents.seek(0, 2)
4275
- ucfsize = fcontents.tell()
4276
- fcontents.seek(0, 0)
4277
- if(compression == "auto"):
4278
- ilsize = len(compressionlistalt)
4279
- ilmin = 0
4280
- ilcsize = []
4281
- while(ilmin < ilsize):
4282
- cfcontents = BytesIO()
4283
- shutil.copyfileobj(fcontents, cfcontents)
4284
- fcontents.seek(0, 0)
4285
- cfcontents.seek(0, 0)
4286
- cfcontents = CompressArchiveFile(
4287
- cfcontents, compressionlistalt[ilmin], compressionlevel, formatspecs)
4288
- if(cfcontents):
4289
- cfcontents.seek(0, 2)
4290
- ilcsize.append(cfcontents.tell())
4291
- cfcontents.close()
4292
- else:
4293
- try:
4294
- ilcsize.append(sys.maxint)
4295
- except AttributeError:
4296
- ilcsize.append(sys.maxsize)
4297
- ilmin = ilmin + 1
4298
- ilcmin = ilcsize.index(min(ilcsize))
4299
- compression = compressionlistalt[ilcmin]
4300
- fcontents.seek(0, 0)
4301
- cfcontents = BytesIO()
4302
- shutil.copyfileobj(fcontents, cfcontents)
4303
- cfcontents.seek(0, 0)
4304
- cfcontents = CompressArchiveFile(
4305
- cfcontents, compression, compressionlevel, formatspecs)
4306
- cfcontents.seek(0, 2)
4307
- cfsize = cfcontents.tell()
4308
- if(ucfsize > cfsize):
4309
- fcsize = format(int(cfsize), 'x').lower()
4310
- fcompression = compression
4311
- fcontents.close()
4312
- fcontents = cfcontents
4304
+ fpc = tarfp.extractfile(member)
4305
+ shutil.copyfileobj(fpc, fcontents)
4306
+ if(not compresswholefile):
4307
+ fcontents.seek(0, 2)
4308
+ ucfsize = fcontents.tell()
4309
+ fcontents.seek(0, 0)
4310
+ if(compression == "auto"):
4311
+ ilsize = len(compressionlistalt)
4312
+ ilmin = 0
4313
+ ilcsize = []
4314
+ while(ilmin < ilsize):
4315
+ cfcontents = BytesIO()
4316
+ fcontents.seek(0, 0)
4317
+ shutil.copyfileobj(fcontents, cfcontents)
4318
+ fcontents.seek(0, 0)
4319
+ cfcontents.seek(0, 0)
4320
+ cfcontents = CompressArchiveFile(
4321
+ cfcontents, compressionlistalt[ilmin], compressionlevel, formatspecs)
4322
+ if(cfcontents):
4323
+ cfcontents.seek(0, 2)
4324
+ ilcsize.append(cfcontents.tell())
4325
+ cfcontents.close()
4326
+ else:
4327
+ try:
4328
+ ilcsize.append(sys.maxint)
4329
+ except AttributeError:
4330
+ ilcsize.append(sys.maxsize)
4331
+ ilmin = ilmin + 1
4332
+ ilcmin = ilcsize.index(min(ilcsize))
4333
+ curcompression = compressionlistalt[ilcmin]
4334
+ fcontents.seek(0, 0)
4335
+ cfcontents = BytesIO()
4336
+ shutil.copyfileobj(fcontents, cfcontents)
4337
+ cfcontents.seek(0, 0)
4338
+ cfcontents = CompressArchiveFile(
4339
+ cfcontents, curcompression, compressionlevel, formatspecs)
4340
+ cfcontents.seek(0, 2)
4341
+ cfsize = cfcontents.tell()
4342
+ if(ucfsize > cfsize):
4343
+ fcsize = format(int(cfsize), 'x').lower()
4344
+ fcompression = curcompression
4345
+ fcontents.close()
4346
+ fcontents = cfcontents
4313
4347
  if(fcompression == "none"):
4314
4348
  fcompression = ""
4315
4349
  fcontents.seek(0, 0)
@@ -4443,16 +4477,16 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4443
4477
  zipinfo = zipfp.getinfo(member.filename)
4444
4478
  if(verbose):
4445
4479
  VerbosePrintOut(fname)
4446
- if(not member.is_dir()):
4447
- fpremode = int(stat.S_IFREG + 438)
4448
- elif(member.is_dir()):
4480
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
4449
4481
  fpremode = int(stat.S_IFDIR + 511)
4482
+ else:
4483
+ fpremode = int(stat.S_IFREG + 438)
4450
4484
  flinkcount = 0
4451
4485
  ftype = 0
4452
- if(not member.is_dir()):
4453
- ftype = 0
4454
- elif(member.is_dir()):
4486
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
4455
4487
  ftype = 5
4488
+ else:
4489
+ ftype = 0
4456
4490
  flinkname = ""
4457
4491
  fcurfid = format(int(curfid), 'x').lower()
4458
4492
  fcurinode = format(int(curfid), 'x').lower()
@@ -4476,14 +4510,14 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4476
4510
  int(time.mktime(member.date_time + (0, 0, -1))), 'x').lower()
4477
4511
  if(zipinfo.create_system == 0 or zipinfo.create_system == 10):
4478
4512
  fwinattributes = format(int(zipinfo.external_attr), 'x').lower()
4479
- if(not member.is_dir()):
4480
- fmode = format(int(stat.S_IFREG + 438), 'x').lower()
4481
- fchmode = stat.S_IMODE(int(stat.S_IFREG + 438))
4482
- ftypemod = stat.S_IFMT(int(stat.S_IFREG + 438))
4483
- elif(member.is_dir()):
4513
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
4484
4514
  fmode = format(int(stat.S_IFDIR + 511), 'x').lower()
4485
4515
  fchmode = stat.S_IMODE(int(stat.S_IFDIR + 511))
4486
4516
  ftypemod = stat.S_IFMT(int(stat.S_IFDIR + 511))
4517
+ else:
4518
+ fmode = format(int(stat.S_IFREG + 438), 'x').lower()
4519
+ fchmode = stat.S_IMODE(int(stat.S_IFREG + 438))
4520
+ ftypemod = stat.S_IFMT(int(stat.S_IFREG + 438))
4487
4521
  elif(zipinfo.create_system == 3):
4488
4522
  fwinattributes = format(int(0), 'x').lower()
4489
4523
  try:
@@ -4498,16 +4532,16 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4498
4532
  ftypemod = stat.S_IFMT(prefmode)
4499
4533
  else:
4500
4534
  fwinattributes = format(int(0), 'x').lower()
4501
- if(not member.is_dir()):
4502
- fmode = format(int(stat.S_IFREG + 438), 'x').lower()
4503
- prefmode = int(stat.S_IFREG + 438)
4504
- fchmode = stat.S_IMODE(prefmode)
4505
- ftypemod = stat.S_IFMT(prefmode)
4506
- elif(member.is_dir()):
4535
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
4507
4536
  fmode = format(int(stat.S_IFDIR + 511), 'x').lower()
4508
4537
  prefmode = int(stat.S_IFDIR + 511)
4509
4538
  fchmode = stat.S_IMODE(prefmode)
4510
4539
  ftypemod = stat.S_IFMT(prefmode)
4540
+ else:
4541
+ fmode = format(int(stat.S_IFREG + 438), 'x').lower()
4542
+ prefmode = int(stat.S_IFREG + 438)
4543
+ fchmode = stat.S_IMODE(prefmode)
4544
+ ftypemod = stat.S_IFMT(prefmode)
4511
4545
  fcompression = ""
4512
4546
  fcsize = format(int(0), 'x').lower()
4513
4547
  try:
@@ -4558,6 +4592,7 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4558
4592
  ilcsize = []
4559
4593
  while(ilmin < ilsize):
4560
4594
  cfcontents = BytesIO()
4595
+ fcontents.seek(0, 0)
4561
4596
  shutil.copyfileobj(fcontents, cfcontents)
4562
4597
  fcontents.seek(0, 0)
4563
4598
  cfcontents.seek(0, 0)
@@ -4568,18 +4603,18 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
4568
4603
  cfcontents.close()
4569
4604
  ilmin = ilmin + 1
4570
4605
  ilcmin = ilcsize.index(min(ilcsize))
4571
- compression = compressionlistalt[ilcmin]
4606
+ curcompression = compressionlistalt[ilcmin]
4572
4607
  fcontents.seek(0, 0)
4573
4608
  cfcontents = BytesIO()
4574
4609
  shutil.copyfileobj(fcontents, cfcontents)
4575
4610
  cfcontents.seek(0, 0)
4576
4611
  cfcontents = CompressArchiveFile(
4577
- cfcontents, compression, compressionlevel, formatspecs)
4612
+ cfcontents, curcompression, compressionlevel, formatspecs)
4578
4613
  cfcontents.seek(0, 2)
4579
4614
  cfsize = cfcontents.tell()
4580
4615
  if(ucfsize > cfsize):
4581
4616
  fcsize = format(int(cfsize), 'x').lower()
4582
- fcompression = compression
4617
+ fcompression = curcompression
4583
4618
  fcontents.close()
4584
4619
  fcontents = cfcontents
4585
4620
  if(fcompression == "none"):
@@ -4855,6 +4890,7 @@ if(rarfile_support):
4855
4890
  ilcsize = []
4856
4891
  while(ilmin < ilsize):
4857
4892
  cfcontents = BytesIO()
4893
+ fcontents.seek(0, 0)
4858
4894
  shutil.copyfileobj(fcontents, cfcontents)
4859
4895
  fcontents.seek(0, 0)
4860
4896
  cfcontents.seek(0, 0)
@@ -4871,13 +4907,13 @@ if(rarfile_support):
4871
4907
  ilcsize.append(sys.maxsize)
4872
4908
  ilmin = ilmin + 1
4873
4909
  ilcmin = ilcsize.index(min(ilcsize))
4874
- compression = compressionlistalt[ilcmin]
4910
+ curcompression = compressionlistalt[ilcmin]
4875
4911
  fcontents.seek(0, 0)
4876
4912
  cfcontents = BytesIO()
4877
4913
  shutil.copyfileobj(fcontents, cfcontents)
4878
4914
  cfcontents.seek(0, 0)
4879
4915
  cfcontents = CompressArchiveFile(
4880
- cfcontents, compression, compressionlevel, formatspecs)
4916
+ cfcontents, curcompression, compressionlevel, formatspecs)
4881
4917
  cfcontents.seek(0, 2)
4882
4918
  cfsize = cfcontents.tell()
4883
4919
  if(ucfsize > cfsize):
@@ -5090,6 +5126,7 @@ if(py7zr_support):
5090
5126
  ilcsize = []
5091
5127
  while(ilmin < ilsize):
5092
5128
  cfcontents = BytesIO()
5129
+ fcontents.seek(0, 0)
5093
5130
  shutil.copyfileobj(fcontents, cfcontents)
5094
5131
  fcontents.seek(0, 0)
5095
5132
  cfcontents.seek(0, 0)
@@ -5106,18 +5143,18 @@ if(py7zr_support):
5106
5143
  ilcsize.append(sys.maxsize)
5107
5144
  ilmin = ilmin + 1
5108
5145
  ilcmin = ilcsize.index(min(ilcsize))
5109
- compression = compressionlistalt[ilcmin]
5146
+ curcompression = compressionlistalt[ilcmin]
5110
5147
  fcontents.seek(0, 0)
5111
5148
  cfcontents = BytesIO()
5112
5149
  shutil.copyfileobj(fcontents, cfcontents)
5113
5150
  cfcontents.seek(0, 0)
5114
5151
  cfcontents = CompressArchiveFile(
5115
- cfcontents, compression, compressionlevel, formatspecs)
5152
+ cfcontents, curcompression, compressionlevel, formatspecs)
5116
5153
  cfcontents.seek(0, 2)
5117
5154
  cfsize = cfcontents.tell()
5118
5155
  if(ucfsize > cfsize):
5119
5156
  fcsize = format(int(cfsize), 'x').lower()
5120
- fcompression = compression
5157
+ fcompression = curcompression
5121
5158
  fcontents.close()
5122
5159
  fcontents = cfcontents
5123
5160
  if(fcompression == "none"):
@@ -5202,7 +5239,7 @@ def ArchiveFileSeekToFileNum(infile, seekto=0, listonly=False, contentasfile=Tru
5202
5239
  if(hasattr(infile, "read") or hasattr(infile, "write")):
5203
5240
  catfp = infile
5204
5241
  catfp.seek(0, 0)
5205
- catfp = UncompressArchiveFile(catfp, formatspecs)
5242
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5206
5243
  checkcompressfile = CheckCompressionSubType(catfp, formatspecs, True)
5207
5244
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
5208
5245
  return TarFileToArray(infile, seekto, 0, listonly, contentasfile, skipchecksum, formatspecs, returnfp)
@@ -5224,7 +5261,7 @@ def ArchiveFileSeekToFileNum(infile, seekto=0, listonly=False, contentasfile=Tru
5224
5261
  else:
5225
5262
  shutil.copyfileobj(sys.stdin, catfp)
5226
5263
  catfp.seek(0, 0)
5227
- catfp = UncompressArchiveFile(catfp, formatspecs)
5264
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5228
5265
  if(not catfp):
5229
5266
  return False
5230
5267
  catfp.seek(0, 0)
@@ -5232,14 +5269,14 @@ def ArchiveFileSeekToFileNum(infile, seekto=0, listonly=False, contentasfile=Tru
5232
5269
  catfp = BytesIO()
5233
5270
  catfp.write(infile)
5234
5271
  catfp.seek(0, 0)
5235
- catfp = UncompressArchiveFile(catfp, formatspecs)
5272
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5236
5273
  if(not catfp):
5237
5274
  return False
5238
5275
  catfp.seek(0, 0)
5239
5276
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5240
5277
  catfp = download_file_from_internet_file(infile)
5241
5278
  catfp.seek(0, 0)
5242
- catfp = UncompressArchiveFile(catfp, formatspecs)
5279
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5243
5280
  if(not catfp):
5244
5281
  return False
5245
5282
  catfp.seek(0, 0)
@@ -5469,7 +5506,7 @@ def ArchiveFileSeekToFileName(infile, seekfile=None, listonly=False, contentasfi
5469
5506
  if(hasattr(infile, "read") or hasattr(infile, "write")):
5470
5507
  catfp = infile
5471
5508
  catfp.seek(0, 0)
5472
- catfp = UncompressArchiveFile(catfp, formatspecs)
5509
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5473
5510
  checkcompressfile = CheckCompressionSubType(catfp, formatspecs, True)
5474
5511
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
5475
5512
  return TarFileToArray(infile, 0, 0, listonly, contentasfile, skipchecksum, formatspecs, returnfp)
@@ -5491,7 +5528,7 @@ def ArchiveFileSeekToFileName(infile, seekfile=None, listonly=False, contentasfi
5491
5528
  else:
5492
5529
  shutil.copyfileobj(sys.stdin, catfp)
5493
5530
  catfp.seek(0, 0)
5494
- catfp = UncompressArchiveFile(catfp, formatspecs)
5531
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5495
5532
  if(not catfp):
5496
5533
  return False
5497
5534
  catfp.seek(0, 0)
@@ -5499,13 +5536,13 @@ def ArchiveFileSeekToFileName(infile, seekfile=None, listonly=False, contentasfi
5499
5536
  catfp = BytesIO()
5500
5537
  catfp.write(infile)
5501
5538
  catfp.seek(0, 0)
5502
- catfp = UncompressArchiveFile(catfp, formatspecs)
5539
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5503
5540
  if(not catfp):
5504
5541
  return False
5505
5542
  catfp.seek(0, 0)
5506
5543
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5507
5544
  catfp = download_file_from_internet_file(infile)
5508
- catfp = UncompressArchiveFile(catfp, formatspecs)
5545
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5509
5546
  catfp.seek(0, 0)
5510
5547
  if(not catfp):
5511
5548
  return False
@@ -5749,7 +5786,7 @@ def ArchiveFileValidate(infile, formatspecs=__file_format_dict__, verbose=False,
5749
5786
  if(hasattr(infile, "read") or hasattr(infile, "write")):
5750
5787
  catfp = infile
5751
5788
  catfp.seek(0, 0)
5752
- catfp = UncompressArchiveFile(catfp, formatspecs)
5789
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5753
5790
  checkcompressfile = CheckCompressionSubType(catfp, formatspecs, True)
5754
5791
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
5755
5792
  return TarFileToArray(infile, 0, 0, False, True, False, formatspecs, returnfp)
@@ -5771,7 +5808,7 @@ def ArchiveFileValidate(infile, formatspecs=__file_format_dict__, verbose=False,
5771
5808
  else:
5772
5809
  shutil.copyfileobj(sys.stdin, catfp)
5773
5810
  catfp.seek(0, 0)
5774
- catfp = UncompressArchiveFile(catfp, formatspecs)
5811
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5775
5812
  if(not catfp):
5776
5813
  return False
5777
5814
  catfp.seek(0, 0)
@@ -5779,13 +5816,13 @@ def ArchiveFileValidate(infile, formatspecs=__file_format_dict__, verbose=False,
5779
5816
  catfp = BytesIO()
5780
5817
  catfp.write(infile)
5781
5818
  catfp.seek(0, 0)
5782
- catfp = UncompressArchiveFile(catfp, formatspecs)
5819
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5783
5820
  if(not catfp):
5784
5821
  return False
5785
5822
  catfp.seek(0, 0)
5786
5823
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
5787
5824
  catfp = download_file_from_internet_file(infile)
5788
- catfp = UncompressArchiveFile(catfp, formatspecs)
5825
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
5789
5826
  catfp.seek(0, 0)
5790
5827
  if(not catfp):
5791
5828
  return False
@@ -6036,7 +6073,7 @@ def ArchiveFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentas
6036
6073
  if(hasattr(infile, "read") or hasattr(infile, "write")):
6037
6074
  catfp = infile
6038
6075
  catfp.seek(0, 0)
6039
- catfp = UncompressArchiveFile(catfp, formatspecs)
6076
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
6040
6077
  checkcompressfile = CheckCompressionSubType(catfp, formatspecs, True)
6041
6078
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
6042
6079
  return TarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, returnfp)
@@ -6058,7 +6095,7 @@ def ArchiveFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentas
6058
6095
  else:
6059
6096
  shutil.copyfileobj(sys.stdin, catfp)
6060
6097
  catfp.seek(0, 0)
6061
- catfp = UncompressArchiveFile(catfp, formatspecs)
6098
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
6062
6099
  if(not catfp):
6063
6100
  return False
6064
6101
  catfp.seek(0, 0)
@@ -6066,13 +6103,13 @@ def ArchiveFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentas
6066
6103
  catfp = BytesIO()
6067
6104
  catfp.write(infile)
6068
6105
  catfp.seek(0, 0)
6069
- catfp = UncompressArchiveFile(catfp, formatspecs)
6106
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
6070
6107
  if(not catfp):
6071
6108
  return False
6072
6109
  catfp.seek(0, 0)
6073
6110
  elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", str(infile))):
6074
6111
  catfp = download_file_from_internet_file(infile)
6075
- catfp = UncompressArchiveFile(catfp, formatspecs)
6112
+ catfp = UncompressBytesAltFP(catfp, formatspecs)
6076
6113
  catfp.seek(0, 0)
6077
6114
  if(not catfp):
6078
6115
  return False
@@ -6340,7 +6377,7 @@ def ArchiveFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentas
6340
6377
  else:
6341
6378
  catfcontents.seek(0, 0)
6342
6379
  if(uncompress):
6343
- catfcontents = UncompressArchiveFile(
6380
+ catfcontents = UncompressBytesAltFP(
6344
6381
  catfcontents, formatspecs)
6345
6382
  catfcontents.seek(0, 0)
6346
6383
  catfccs = GetFileChecksum(
@@ -6880,8 +6917,8 @@ def TarFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
6880
6917
  fcsize = 0
6881
6918
  fcontents = BytesIO()
6882
6919
  if ftype in data_types:
6883
- with tarfp.extractfile(member) as fpc:
6884
- shutil.copyfileobj(fpc, fcontents)
6920
+ fpc = tarfp.extractfile(member)
6921
+ shutil.copyfileobj(fpc, fcontents)
6885
6922
  fcontents.seek(0, 0)
6886
6923
  ftypehex = format(ftype, 'x').lower()
6887
6924
  extrafields = len(extradata)
@@ -7018,16 +7055,16 @@ def ZipFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
7018
7055
  zipinfo = zipfp.getinfo(member.filename)
7019
7056
  if(verbose):
7020
7057
  VerbosePrintOut(fname)
7021
- if(not member.is_dir()):
7022
- fpremode = stat.S_IFREG + 438
7023
- elif(member.is_dir()):
7058
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
7024
7059
  fpremode = stat.S_IFDIR + 511
7060
+ else:
7061
+ fpremode = stat.S_IFREG + 438
7025
7062
  flinkcount = 0
7026
7063
  ftype = 0
7027
- if(not member.is_dir()):
7028
- ftype = 0
7029
- elif(member.is_dir()):
7064
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
7030
7065
  ftype = 5
7066
+ else:
7067
+ ftype = 0
7031
7068
  flinkname = ""
7032
7069
  fbasedir = os.path.dirname(fname)
7033
7070
  fcurfid = curfid
@@ -7049,14 +7086,14 @@ def ZipFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
7049
7086
  fbtime = time.mktime(member.date_time + (0, 0, -1))
7050
7087
  if(zipinfo.create_system == 0 or zipinfo.create_system == 10):
7051
7088
  fwinattributes = int(zipinfo.external_attr)
7052
- if(not member.is_dir()):
7053
- fmode = int(stat.S_IFREG + 438)
7054
- fchmode = int(stat.S_IMODE(int(stat.S_IFREG + 438)))
7055
- ftypemod = int(stat.S_IFMT(int(stat.S_IFREG + 438)))
7056
- elif(member.is_dir()):
7089
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
7057
7090
  fmode = int(stat.S_IFDIR + 511)
7058
7091
  fchmode = int(stat.S_IMODE(int(stat.S_IFDIR + 511)))
7059
7092
  ftypemod = int(stat.S_IFMT(int(stat.S_IFDIR + 511)))
7093
+ else:
7094
+ fmode = int(stat.S_IFREG + 438)
7095
+ fchmode = int(stat.S_IMODE(int(stat.S_IFREG + 438)))
7096
+ ftypemod = int(stat.S_IFMT(int(stat.S_IFREG + 438)))
7060
7097
  elif(zipinfo.create_system == 3):
7061
7098
  fwinattributes = int(0)
7062
7099
  try:
@@ -7069,14 +7106,14 @@ def ZipFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
7069
7106
  ftypemod = stat.S_IFMT(fmode)
7070
7107
  else:
7071
7108
  fwinattributes = int(0)
7072
- if(not member.is_dir()):
7073
- fmode = int(stat.S_IFREG + 438)
7074
- fchmode = int(stat.S_IMODE(int(stat.S_IFREG + 438)))
7075
- ftypemod = int(stat.S_IFMT(int(stat.S_IFREG + 438)))
7076
- elif(member.is_dir()):
7109
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
7077
7110
  fmode = int(stat.S_IFDIR + 511)
7078
7111
  fchmode = int(stat.S_IMODE(int(stat.S_IFDIR + 511)))
7079
7112
  ftypemod = int(stat.S_IFMT(int(stat.S_IFDIR + 511)))
7113
+ else:
7114
+ fmode = int(stat.S_IFREG + 438)
7115
+ fchmode = int(stat.S_IMODE(int(stat.S_IFREG + 438)))
7116
+ ftypemod = int(stat.S_IFMT(int(stat.S_IFREG + 438)))
7080
7117
  fcompression = ""
7081
7118
  fcsize = 0
7082
7119
  try:
@@ -7860,6 +7897,7 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7860
7897
  ilcsize = []
7861
7898
  while(ilmin < ilsize):
7862
7899
  cfcontents = BytesIO()
7900
+ fcontents.seek(0, 0)
7863
7901
  shutil.copyfileobj(fcontents, cfcontents)
7864
7902
  fcontents.seek(0, 0)
7865
7903
  cfcontents.seek(0, 0)
@@ -7876,18 +7914,18 @@ def RePackArchiveFile(infile, outfile, compression="auto", compresswholefile=Tru
7876
7914
  ilcsize.append(sys.maxsize)
7877
7915
  ilmin = ilmin + 1
7878
7916
  ilcmin = ilcsize.index(min(ilcsize))
7879
- compression = compressionlistalt[ilcmin]
7917
+ curcompression = compressionlistalt[ilcmin]
7880
7918
  fcontents.seek(0, 0)
7881
7919
  cfcontents = BytesIO()
7882
7920
  shutil.copyfileobj(fcontents, cfcontents)
7883
7921
  cfcontents.seek(0, 0)
7884
7922
  cfcontents = CompressArchiveFile(
7885
- cfcontents, compression, compressionlevel, formatspecs)
7923
+ cfcontents, curcompression, compressionlevel, formatspecs)
7886
7924
  cfcontents.seek(0, 2)
7887
7925
  cfsize = cfcontents.tell()
7888
7926
  if(ucfsize > cfsize):
7889
7927
  fcsize = format(int(cfsize), 'x').lower()
7890
- fcompression = compression
7928
+ fcompression = curcompression
7891
7929
  fcontents.close()
7892
7930
  fcontents = cfcontents
7893
7931
  if(followlink):
@@ -8494,7 +8532,6 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
8494
8532
  try:
8495
8533
  zipfp = zipfile.ZipFile(infile, "r", allowZip64=True)
8496
8534
  except FileNotFoundError:
8497
- print(6)
8498
8535
  return False
8499
8536
  lcfi = 0
8500
8537
  returnval = {}
@@ -8502,16 +8539,17 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
8502
8539
  if(ziptest):
8503
8540
  VerbosePrintOut("Bad file found!")
8504
8541
  for member in sorted(zipfp.infolist(), key=lambda x: x.filename):
8542
+ zipinfo = zipfp.getinfo(member.filename)
8505
8543
  if(zipinfo.create_system == 0 or zipinfo.create_system == 10):
8506
8544
  fwinattributes = int(zipinfo.external_attr)
8507
- if(not member.is_dir()):
8508
- fmode = int(stat.S_IFREG + 438)
8509
- fchmode = int(stat.S_IMODE(fmode))
8510
- ftypemod = int(stat.S_IFMT(fmode))
8511
- elif(member.is_dir()):
8545
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
8512
8546
  fmode = int(stat.S_IFDIR + 511)
8513
8547
  fchmode = int(stat.S_IMODE(int(stat.S_IFDIR + 511)))
8514
8548
  ftypemod = int(stat.S_IFMT(int(stat.S_IFDIR + 511)))
8549
+ else:
8550
+ fmode = int(stat.S_IFREG + 438)
8551
+ fchmode = int(stat.S_IMODE(fmode))
8552
+ ftypemod = int(stat.S_IFMT(fmode))
8515
8553
  elif(zipinfo.create_system == 3):
8516
8554
  fwinattributes = int(0)
8517
8555
  try:
@@ -8524,14 +8562,14 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
8524
8562
  ftypemod = stat.S_IFMT(fmode)
8525
8563
  else:
8526
8564
  fwinattributes = int(0)
8527
- if(not member.is_dir()):
8528
- fmode = int(stat.S_IFREG + 438)
8529
- fchmode = int(stat.S_IMODE(fmode))
8530
- ftypemod = int(stat.S_IFMT(fmode))
8531
- elif(member.is_dir()):
8565
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
8532
8566
  fmode = int(stat.S_IFDIR + 511)
8533
8567
  fchmode = int(stat.S_IMODE(int(stat.S_IFDIR + 511)))
8534
8568
  ftypemod = int(stat.S_IFMT(int(stat.S_IFDIR + 511)))
8569
+ else:
8570
+ fmode = int(stat.S_IFREG + 438)
8571
+ fchmode = int(stat.S_IMODE(fmode))
8572
+ ftypemod = int(stat.S_IFMT(fmode))
8535
8573
  returnval.update({lcfi: member.filename})
8536
8574
  if(not verbose):
8537
8575
  VerbosePrintOut(member.filename)
@@ -8542,12 +8580,12 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
8542
8580
  for fmodval in str(oct(fmode))[-3:]:
8543
8581
  permissionstr = permissionstr + \
8544
8582
  permissions['access'].get(fmodval, '---')
8545
- if(not member.is_dir()):
8546
- ftype = 0
8547
- permissionstr = "-" + permissionstr
8548
- elif(member.is_dir()):
8583
+ if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
8549
8584
  ftype = 5
8550
8585
  permissionstr = "d" + permissionstr
8586
+ else:
8587
+ ftype = 0
8588
+ permissionstr = "-" + permissionstr
8551
8589
  printfname = member.filename
8552
8590
  try:
8553
8591
  fuid = int(os.getuid())
@@ -9406,7 +9444,7 @@ def download_file_from_internet_file(url, headers=geturls_headers_pycatfile_pyth
9406
9444
  def download_file_from_internet_uncompress_file(url, headers=geturls_headers_pycatfile_python_alt, formatspecs=__file_format_dict__):
9407
9445
  formatspecs = FormatSpecsListToDict(formatspecs)
9408
9446
  fp = download_file_from_internet_file(url)
9409
- fp = UncompressArchiveFile(fp, formatspecs)
9447
+ fp = UncompressBytesAltFP(fp, formatspecs)
9410
9448
  fp.seek(0, 0)
9411
9449
  if(not fp):
9412
9450
  return False
@@ -9432,7 +9470,7 @@ def download_file_from_internet_string(url, headers=geturls_headers_pycatfile_py
9432
9470
  def download_file_from_internet_uncompress_string(url, headers=geturls_headers_pycatfile_python_alt, formatspecs=__file_format_dict__):
9433
9471
  formatspecs = FormatSpecsListToDict(formatspecs)
9434
9472
  fp = download_file_from_internet_string(url)
9435
- fp = UncompressArchiveFile(fp, formatspecs)
9473
+ fp = UncompressBytesAltFP(fp, formatspecs)
9436
9474
  fp.seek(0, 0)
9437
9475
  if(not fp):
9438
9476
  return False
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes