PyFoxFile 0.21.0__py3-none-any.whl → 0.21.4__py3-none-any.whl

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.
pyfoxfile.py CHANGED
@@ -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: pyfoxfile.py - Last Update: 9/17/2025 Ver. 0.21.0 RC 1 - Author: cooldude2k $
17
+ $FileInfo: pyfoxfile.py - Last Update: 8/26/2025 Ver. 0.21.4 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
@@ -32,10 +32,12 @@ import socket
32
32
  import hashlib
33
33
  import inspect
34
34
  import datetime
35
+ import tempfile
35
36
  import logging
36
37
  import zipfile
37
38
  import binascii
38
39
  import platform
40
+ from io import StringIO, BytesIO
39
41
  try:
40
42
  from backports import tempfile
41
43
  except ImportError:
@@ -243,17 +245,6 @@ except ImportError:
243
245
  from urllib2 import Request, build_opener, HTTPBasicAuthHandler
244
246
  from urlparse import urlparse
245
247
 
246
- # StringIO and BytesIO
247
- try:
248
- from io import StringIO, BytesIO
249
- except ImportError:
250
- try:
251
- from cStringIO import StringIO
252
- from cStringIO import StringIO as BytesIO
253
- except ImportError:
254
- from StringIO import StringIO
255
- from StringIO import StringIO as BytesIO
256
-
257
248
  def get_importing_script_path():
258
249
  # Inspect the stack and get the frame of the caller
259
250
  stack = inspect.stack()
@@ -275,22 +266,6 @@ def get_default_threads():
275
266
 
276
267
 
277
268
  __use_pysftp__ = False
278
- __use_alt_format__ = False
279
- __use_env_file__ = True
280
- __use_ini_file__ = True
281
- __use_ini_name__ = "foxfile.ini"
282
- if('PYARCHIVEFILE_CONFIG_FILE' in os.environ and os.path.exists(os.environ['PYARCHIVEFILE_CONFIG_FILE']) and __use_env_file__):
283
- scriptconf = os.environ['PYARCHIVEFILE_CONFIG_FILE']
284
- else:
285
- prescriptpath = get_importing_script_path()
286
- if(prescriptpath is not None):
287
- scriptconf = os.path.join(os.path.dirname(prescriptpath), __use_ini_name__)
288
- else:
289
- scriptconf = ""
290
- if os.path.exists(scriptconf):
291
- __config_file__ = scriptconf
292
- else:
293
- __config_file__ = os.path.join(os.path.dirname(os.path.realpath(__file__)), __use_ini_name__)
294
269
  if(not havepysftp):
295
270
  __use_pysftp__ = False
296
271
  __use_http_lib__ = "httpx"
@@ -328,7 +303,25 @@ def is_only_nonprintable(var):
328
303
  __file_format_multi_dict__ = {}
329
304
  __file_format_default__ = "FoxFile"
330
305
  __include_defaults__ = True
306
+ __use_inmemfile__ = False
331
307
  __program_name__ = "Py"+__file_format_default__
308
+ __use_env_file__ = True
309
+ __use_ini_file__ = True
310
+ __use_ini_name__ = "foxfile.ini"
311
+ __use_json_file__ = False
312
+ __use_json_name__ = "foxfile.json"
313
+ if('PYARCHIVEFILE_CONFIG_FILE' in os.environ and os.path.exists(os.environ['PYARCHIVEFILE_CONFIG_FILE']) and __use_env_file__):
314
+ scriptconf = os.environ['PYARCHIVEFILE_CONFIG_FILE']
315
+ else:
316
+ prescriptpath = get_importing_script_path()
317
+ if(prescriptpath is not None):
318
+ scriptconf = os.path.join(os.path.dirname(prescriptpath), __use_ini_name__)
319
+ else:
320
+ scriptconf = ""
321
+ if os.path.exists(scriptconf):
322
+ __config_file__ = scriptconf
323
+ else:
324
+ __config_file__ = os.path.join(os.path.dirname(os.path.realpath(__file__)), __use_ini_name__)
332
325
  if __use_ini_file__ and os.path.exists(__config_file__):
333
326
  config = configparser.ConfigParser()
334
327
  config.read(__config_file__)
@@ -340,6 +333,7 @@ if __use_ini_file__ and os.path.exists(__config_file__):
340
333
  __file_format_default__ = decode_unicode_escape(config.get('config', 'default'))
341
334
  __program_name__ = decode_unicode_escape(config.get('config', 'proname'))
342
335
  __include_defaults__ = config.getboolean('config', 'includedef')
336
+ __use_inmemfile__ = config.getboolean('config', 'inmemfile')
343
337
  # Loop through all sections
344
338
  for section in config.sections():
345
339
  required_keys = [
@@ -389,12 +383,13 @@ __file_format_extension__ = __file_format_multi_dict__[__file_format_default__][
389
383
  __file_format_dict__ = __file_format_multi_dict__[__file_format_default__]
390
384
  __project__ = __program_name__
391
385
  __project_url__ = "https://github.com/GameMaker2k/PyFoxFile"
392
- __version_info__ = (0, 21, 0, "RC 1", 1)
393
- __version_date_info__ = (2025, 9, 17, "RC 1", 1)
386
+ __version_info__ = (0, 21, 4, "RC 1", 1)
387
+ __version_info__ = (0, 21, 4, "RC 1", 1)
388
+ __version_date_info__ = (2025, 9, 26, "RC 1", 1)
394
389
  __version_date__ = str(__version_date_info__[0]) + "." + str(
395
390
  __version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
396
391
  __revision__ = __version_info__[3]
397
- __revision_id__ = "$Id: 6208d3cb66a43a7e1047211a926f92f6aecfff08 $"
392
+ __revision_id__ = "$Id: 9911cc0b37bf3b39652ce61ec29c1e2180f46e43 $"
398
393
  if(__version_info__[4] is not None):
399
394
  __version_date_plusrc__ = __version_date__ + \
400
395
  "-" + str(__version_date_info__[4])
@@ -584,6 +579,105 @@ def VerbosePrintOutReturn(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
584
579
  return dbgtxt
585
580
 
586
581
 
582
+ # --- Helpers ---
583
+ def _normalize_initial_data(data, isbytes, encoding):
584
+ """Return data in the correct type for write(): bytes (if isbytes) or text (if not)."""
585
+ if data is None:
586
+ return None
587
+
588
+ if isbytes:
589
+ # Want bytes
590
+ if isinstance(data, bytes):
591
+ return data
592
+ # Py2: str is already bytes, unicode needs encode
593
+ if sys.version_info[0] == 2:
594
+ try:
595
+ unicode # noqa: F821
596
+ except NameError:
597
+ pass
598
+ else:
599
+ if isinstance(data, unicode): # noqa: F821
600
+ return data.encode(encoding)
601
+ # Py3 str -> encode
602
+ return str(data).encode(encoding)
603
+ else:
604
+ # Want text (unicode/str)
605
+ if sys.version_info[0] == 2:
606
+ try:
607
+ unicode # noqa: F821
608
+ if isinstance(data, unicode): # noqa: F821
609
+ return data
610
+ # bytes/str -> decode
611
+ return data.decode(encoding) if isinstance(data, str) else unicode(data) # noqa: F821
612
+ except NameError:
613
+ # Very defensive; shouldn't happen
614
+ return data
615
+ else:
616
+ # Py3: want str
617
+ if isinstance(data, bytes):
618
+ return data.decode(encoding)
619
+ return str(data)
620
+
621
+
622
+ def MkTempFile(data=None, inmem=__use_inmemfile__, isbytes=True, prefix=__project__,
623
+ delete=True, encoding="utf-8"):
624
+ """
625
+ Return a file-like handle.
626
+ - If inmem=True: returns StringIO (text) or BytesIO (bytes).
627
+ - If inmem=False: returns a NamedTemporaryFile opened in text or binary mode.
628
+ Args:
629
+ data: optional initial content; if provided, it's written and the handle is seek(0)
630
+ inmem: bool — return in-memory handle if True
631
+ isbytes: bool — choose bytes (True) or text (False)
632
+ prefix: str — tempfile prefix
633
+ delete: bool — whether the tempfile is deleted on close (NamedTemporaryFile)
634
+ encoding: str — used for text mode (and for conversions when needed)
635
+ """
636
+ init = _normalize_initial_data(data, isbytes, encoding)
637
+
638
+ if inmem:
639
+ buf = BytesIO() if isbytes else StringIO()
640
+ if init is not None:
641
+ buf.write(init)
642
+ buf.seek(0)
643
+ return buf
644
+
645
+ mode = "wb+" if isbytes else "w+"
646
+ kwargs = {"prefix": prefix or "", "delete": delete, "mode": mode}
647
+
648
+ # Only Python 3's text-mode files accept encoding/newline explicitly
649
+ if not isbytes and sys.version_info[0] >= 3:
650
+ kwargs["encoding"] = encoding
651
+ kwargs["newline"] = ""
652
+
653
+ f = tempfile.NamedTemporaryFile(**kwargs)
654
+
655
+ if init is not None:
656
+ f.write(init)
657
+ f.seek(0)
658
+ return f
659
+
660
+
661
+ def MkTempFileSmart(data=None, isbytes=True, prefix=__project__, max_mem=1024*1024, encoding="utf-8"):
662
+ """
663
+ Spooled temp file: starts in memory and spills to disk past max_mem.
664
+ Behaves like BytesIO/StringIO for small data, with the same preload+seek(0) behavior.
665
+ """
666
+ mode = "wb+" if isbytes else "w+"
667
+ kwargs = {"mode": mode, "max_size": max_mem, "prefix": prefix or ""}
668
+ if not isbytes and sys.version_info[0] >= 3:
669
+ kwargs["encoding"] = encoding
670
+ kwargs["newline"] = ""
671
+
672
+ f = tempfile.SpooledTemporaryFile(**kwargs)
673
+
674
+ init = _normalize_initial_data(data, isbytes, encoding)
675
+ if init is not None:
676
+ f.write(init)
677
+ f.seek(0)
678
+ return f
679
+
680
+
587
681
  def RemoveWindowsPath(dpath):
588
682
  """
589
683
  Normalize a path by converting backslashes to forward slashes
@@ -1920,7 +2014,7 @@ def ReadFileHeaderDataBySize(fp, delimiter=__file_format_dict__['format_delimite
1920
2014
  headersize = int(preheaderdata[0], 16)
1921
2015
  if(headersize <= 0):
1922
2016
  return []
1923
- subfp = BytesIO()
2017
+ subfp = MkTempFile()
1924
2018
  subfp.write(fp.read(headersize))
1925
2019
  fp.seek(len(delimiter), 1)
1926
2020
  subfp.seek(0, 0)
@@ -1957,15 +2051,15 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
1957
2051
  HeaderOut = ReadFileHeaderDataWoSize(fp, delimiter)
1958
2052
  if(len(HeaderOut) == 0):
1959
2053
  return False
1960
- if(re.findall("^[.|/]", HeaderOut[3])):
1961
- fname = HeaderOut[3]
2054
+ if(re.findall("^[.|/]", HeaderOut[5])):
2055
+ fname = HeaderOut[5]
1962
2056
  else:
1963
- fname = "./"+HeaderOut[3]
2057
+ fname = "./"+HeaderOut[5]
1964
2058
  fcs = HeaderOut[-2].lower()
1965
2059
  fccs = HeaderOut[-1].lower()
1966
- fsize = int(HeaderOut[5], 16)
1967
- fcompression = HeaderOut[12]
1968
- fcsize = int(HeaderOut[13], 16)
2060
+ fsize = int(HeaderOut[7], 16)
2061
+ fcompression = HeaderOut[14]
2062
+ fcsize = int(HeaderOut[15], 16)
1969
2063
  fseeknextfile = HeaderOut[26]
1970
2064
  fjsontype = HeaderOut[27]
1971
2065
  fjsonlen = int(HeaderOut[28], 16)
@@ -2004,7 +2098,7 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
2004
2098
  return False
2005
2099
  fhend = fp.tell() - 1
2006
2100
  fcontentstart = fp.tell()
2007
- fcontents = BytesIO()
2101
+ fcontents = MkTempFile()
2008
2102
  if(fsize > 0 and not listonly):
2009
2103
  if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
2010
2104
  fcontents.write(fp.read(fsize))
@@ -2018,6 +2112,7 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
2018
2112
  fcontents.seek(0, 0)
2019
2113
  newfccs = GetFileChecksum(
2020
2114
  fcontents.read(), HeaderOut[-3].lower(), False, formatspecs)
2115
+ fcontents.seek(0, 0)
2021
2116
  if(fccs != newfccs and not skipchecksum and not listonly):
2022
2117
  VerbosePrintOut("File Content Checksum Error with file " +
2023
2118
  fname + " at offset " + str(fcontentstart))
@@ -2030,7 +2125,7 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
2030
2125
  if(uncompress):
2031
2126
  cfcontents = UncompressFileAlt(fcontents, formatspecs)
2032
2127
  cfcontents.seek(0, 0)
2033
- cfcontents.seek(0, 0)
2128
+ fcontents = MkTempFile()
2034
2129
  shutil.copyfileobj(cfcontents, fcontents)
2035
2130
  cfcontents.close()
2036
2131
  fcontents.seek(0, 0)
@@ -2122,6 +2217,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2122
2217
  fextrafieldslist = json.loads(fextrafieldslist[0])
2123
2218
  except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
2124
2219
  pass
2220
+ fjstart = fp.tell()
2125
2221
  if(fjsontype=="json"):
2126
2222
  fjsoncontent = {}
2127
2223
  fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
@@ -2143,17 +2239,17 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2143
2239
  fjsoncontent = {}
2144
2240
  elif(fjsontype=="list"):
2145
2241
  fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
2146
- flisttmp = BytesIO()
2242
+ flisttmp = MkTempFile()
2147
2243
  flisttmp.write(fprejsoncontent.encode())
2148
2244
  flisttmp.seek(0)
2149
2245
  fjsoncontent = ReadFileHeaderData(flisttmp, fjsonlen, delimiter)
2150
2246
  flisttmp.close()
2151
2247
  fjsonrawcontent = fjsoncontent
2152
- if(outfjsonlen==1):
2248
+ if(fjsonlen==1):
2153
2249
  try:
2154
2250
  fjsonrawcontent = base64.b64decode(fjsoncontent[0]).decode("UTF-8")
2155
2251
  fjsoncontent = json.loads(base64.b64decode(fjsoncontent[0]).decode("UTF-8"))
2156
- outfjsonlen = len(fjsoncontent)
2252
+ fjsonlen = len(fjsoncontent)
2157
2253
  except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
2158
2254
  try:
2159
2255
  fjsonrawcontent = fjsoncontent[0]
@@ -2161,6 +2257,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2161
2257
  except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
2162
2258
  pass
2163
2259
  fp.seek(len(delimiter), 1)
2260
+ fjend = fp.tell() - 1
2164
2261
  jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs)
2165
2262
  if(jsonfcs != fjsonchecksum and not skipchecksum):
2166
2263
  VerbosePrintOut("File JSON Data Checksum Error with file " +
@@ -2178,7 +2275,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2178
2275
  return False
2179
2276
  fhend = fp.tell() - 1
2180
2277
  fcontentstart = fp.tell()
2181
- fcontents = BytesIO()
2278
+ fcontents = MkTempFile()
2182
2279
  pyhascontents = False
2183
2280
  if(fsize > 0 and not listonly):
2184
2281
  if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
@@ -2195,6 +2292,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2195
2292
  fcontents.seek(0, 0)
2196
2293
  newfccs = GetFileChecksum(
2197
2294
  fcontents.read(), HeaderOut[-3].lower(), False, formatspecs)
2295
+ fcontents.seek(0, 0)
2198
2296
  if(fccs != newfccs and not skipchecksum and not listonly):
2199
2297
  VerbosePrintOut("File Content Checksum Error with file " +
2200
2298
  fname + " at offset " + str(fcontentstart))
@@ -2208,7 +2306,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2208
2306
  cfcontents = UncompressFileAlt(
2209
2307
  fcontents, formatspecs)
2210
2308
  cfcontents.seek(0, 0)
2211
- fcontents = BytesIO()
2309
+ fcontents = MkTempFile()
2212
2310
  shutil.copyfileobj(cfcontents, fcontents)
2213
2311
  cfcontents.close()
2214
2312
  fcontents.seek(0, 0)
@@ -2236,7 +2334,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
2236
2334
  if(not contentasfile):
2237
2335
  fcontents = fcontents.read()
2238
2336
  outlist = {'fheadersize': fheadsize, 'fhstart': fheaderstart, 'fhend': fhend, 'ftype': ftype, 'fencoding': fencoding, 'fcencoding': fcencoding, '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,
2239
- 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': fseeknextfile, 'fheaderchecksumtype': HeaderOut[-4], 'fjsonchecksumtype': outfjsonchecksumtype, 'fcontentchecksumtype': HeaderOut[-3], 'fnumfields': fnumfields + 2, 'frawheader': HeaderOut, 'fextrafields': fextrafields, 'fextrafieldsize': fextrasize, 'fextradata': fextrafieldslist, 'fjsontype': fjsontype, 'fjsonlen': fjsonlen, 'fjsonsize': fjsonsize, 'fjsonrawdata': fjsonrawcontent, 'fjsondata': fjsoncontent, 'fjstart': outfjstart, 'fjend': outfjend, 'fheaderchecksum': fcs, 'fjsonchecksum': outfjsonchecksum, 'fcontentchecksum': fccs, 'fhascontents': pyhascontents, 'fcontentstart': fcontentstart, 'fcontentend': fcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents}
2337
+ 'fdev': fdev, 'fminor': fdev_minor, 'fmajor': fdev_major, 'fseeknextfile': fseeknextfile, 'fheaderchecksumtype': HeaderOut[-4], 'fjsonchecksumtype': fjsonchecksumtype, 'fcontentchecksumtype': HeaderOut[-3], 'fnumfields': fnumfields + 2, 'frawheader': HeaderOut, 'fextrafields': fextrafields, 'fextrafieldsize': fextrasize, 'fextradata': fextrafieldslist, 'fjsontype': fjsontype, 'fjsonlen': fjsonlen, 'fjsonsize': fjsonsize, 'fjsonrawdata': fjsonrawcontent, 'fjsondata': fjsoncontent, 'fjstart': fjstart, 'fjend': fjend, 'fheaderchecksum': fcs, 'fjsonchecksum': fjsonchecksum, 'fcontentchecksum': fccs, 'fhascontents': pyhascontents, 'fcontentstart': fcontentstart, 'fcontentend': fcontentend, 'fcontentasfile': contentasfile, 'fcontents': fcontents}
2240
2338
  return outlist
2241
2339
 
2242
2340
 
@@ -2327,17 +2425,17 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
2327
2425
  fjsoncontent = {}
2328
2426
  elif(fjsontype=="list"):
2329
2427
  fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
2330
- flisttmp = BytesIO()
2428
+ flisttmp = MkTempFile()
2331
2429
  flisttmp.write(fprejsoncontent.encode())
2332
2430
  flisttmp.seek(0)
2333
2431
  fjsoncontent = ReadFileHeaderData(flisttmp, fjsonlen, delimiter)
2334
2432
  flisttmp.close()
2335
2433
  fjsonrawcontent = fjsoncontent
2336
- if(fextrafields==1):
2434
+ if(fjsonlen==1):
2337
2435
  try:
2338
2436
  fjsonrawcontent = base64.b64decode(fjsoncontent[0]).decode("UTF-8")
2339
2437
  fjsoncontent = json.loads(base64.b64decode(fjsoncontent[0]).decode("UTF-8"))
2340
- fextrafields = len(fjsoncontent)
2438
+ fjsonlen = len(fjsoncontent)
2341
2439
  except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
2342
2440
  try:
2343
2441
  fjsonrawcontent = fjsoncontent[0]
@@ -2362,7 +2460,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
2362
2460
  return False
2363
2461
  fhend = fp.tell() - 1
2364
2462
  fcontentstart = fp.tell()
2365
- fcontents = BytesIO()
2463
+ fcontents = MkTempFile()
2366
2464
  pyhascontents = False
2367
2465
  if(fsize > 0 and not listonly):
2368
2466
  if(fcompression == "none" or fcompression == "" or fcompression == "auto"):
@@ -2392,7 +2490,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
2392
2490
  cfcontents = UncompressFileAlt(
2393
2491
  fcontents, formatspecs)
2394
2492
  cfcontents.seek(0, 0)
2395
- fcontents = BytesIO()
2493
+ fcontents = MkTempFile()
2396
2494
  shutil.copyfileobj(cfcontents, fcontents)
2397
2495
  cfcontents.close()
2398
2496
  fcontents.seek(0, 0)
@@ -2547,11 +2645,11 @@ def ReadFileDataWithContentToArray(fp, seekstart=0, seekend=0, listonly=False, c
2547
2645
  formversions = re.search('(.*?)(\\d+)', formstring).groups()
2548
2646
  fcompresstype = ""
2549
2647
  outlist = {'fnumfiles': fnumfiles, 'fformat': formversions[0], 'fcompression': fcompresstype, 'fencoding': fhencoding, 'fversion': formversions[1], 'fostype': fostype, 'fheadersize': fheadsize, 'fsize': CatSizeEnd, 'fnumfields': fnumfields + 2, 'fformatspecs': formatspecs, 'fchecksumtype': fprechecksumtype, 'fheaderchecksum': fprechecksum, 'frawheader': [formstring] + inheader, 'fextrafields': fnumextrafields, 'fextrafieldsize': fnumextrafieldsize, 'fextradata': fextrafieldslist, 'ffilelist': []}
2550
- if(seekstart < 0 and seekstart > fnumfiles):
2648
+ if (seekstart < 0) or (seekstart > fnumfiles):
2551
2649
  seekstart = 0
2552
- if(seekend == 0 or seekend > fnumfiles and seekend < seekstart):
2650
+ if (seekend == 0) or (seekend > fnumfiles) or (seekend < seekstart):
2553
2651
  seekend = fnumfiles
2554
- elif(seekend < 0 and abs(seekend) <= fnumfiles and abs(seekend) >= seekstart):
2652
+ elif (seekend < 0) and (abs(seekend) <= fnumfiles) and (abs(seekend) >= seekstart):
2555
2653
  seekend = fnumfiles - abs(seekend)
2556
2654
  if(seekstart > 0):
2557
2655
  il = 0
@@ -2562,14 +2660,18 @@ def ReadFileDataWithContentToArray(fp, seekstart=0, seekend=0, listonly=False, c
2562
2660
  if(len(preheaderdata) == 0):
2563
2661
  break
2564
2662
  prefsize = int(preheaderdata[5], 16)
2663
+ if(re.findall("^[.|/]", preheaderdata[5])):
2664
+ prefname = preheaderdata[5]
2665
+ else:
2666
+ prefname = "./"+preheaderdata[5]
2565
2667
  prefseeknextfile = preheaderdata[26]
2566
2668
  prefjsonlen = int(preheaderdata[28], 16)
2567
2669
  prefjsonsize = int(preheaderdata[29], 16)
2568
2670
  prefjsonchecksumtype = preheaderdata[30]
2569
2671
  prefjsonchecksum = preheaderdata[31]
2570
- prefprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
2672
+ prejsoncontent = fp.read(prefjsonsize).decode("UTF-8")
2571
2673
  fp.seek(len(delimiter), 1)
2572
- prejsonfcs = GetFileChecksum(fprejsoncontent, prefjsonchecksumtype, True, formatspecs)
2674
+ prejsonfcs = GetFileChecksum(prejsoncontent, prefjsonchecksumtype, True, formatspecs)
2573
2675
  if(prejsonfcs != prefjsonchecksum and not skipchecksum):
2574
2676
  VerbosePrintOut("File JSON Data Checksum Error with file " +
2575
2677
  prefname + " at offset " + str(prefhstart))
@@ -2579,7 +2681,7 @@ def ReadFileDataWithContentToArray(fp, seekstart=0, seekend=0, listonly=False, c
2579
2681
  preheaderdata[:-2], preheaderdata[-4].lower(), True, formatspecs)
2580
2682
  prefcs = preheaderdata[-2]
2581
2683
  if(prefcs != prenewfcs and not skipchecksum):
2582
- VVerbosePrintOut("File Header Checksum Error with file " +
2684
+ VerbosePrintOut("File Header Checksum Error with file " +
2583
2685
  prefname + " at offset " + str(prefhstart))
2584
2686
  VerbosePrintOut("'" + prefcs + "' != " +
2585
2687
  "'" + prenewfcs + "'")
@@ -2588,7 +2690,7 @@ def ReadFileDataWithContentToArray(fp, seekstart=0, seekend=0, listonly=False, c
2588
2690
  invalid_archive = True
2589
2691
  prefhend = fp.tell() - 1
2590
2692
  prefcontentstart = fp.tell()
2591
- prefcontents = BytesIO()
2693
+ prefcontents = MkTempFile()
2592
2694
  pyhascontents = False
2593
2695
  if(prefsize > 0):
2594
2696
  prefcontents.write(fp.read(prefsize))
@@ -2702,11 +2804,11 @@ def ReadFileDataWithContentToList(fp, seekstart=0, seekend=0, listonly=False, co
2702
2804
  return False
2703
2805
  formversions = re.search('(.*?)(\\d+)', formstring).groups()
2704
2806
  outlist = []
2705
- if(seekstart < 0 and seekstart > fnumfiles):
2807
+ if (seekstart < 0) or (seekstart > fnumfiles):
2706
2808
  seekstart = 0
2707
- if(seekend == 0 or seekend > fnumfiles and seekend < seekstart):
2809
+ if (seekend == 0) or (seekend > fnumfiles) or (seekend < seekstart):
2708
2810
  seekend = fnumfiles
2709
- elif(seekend < 0 and abs(seekend) <= fnumfiles and abs(seekend) >= seekstart):
2811
+ elif (seekend < 0) and (abs(seekend) <= fnumfiles) and (abs(seekend) >= seekstart):
2710
2812
  seekend = fnumfiles - abs(seekend)
2711
2813
  if(seekstart > 0):
2712
2814
  il = 0
@@ -2721,16 +2823,20 @@ def ReadFileDataWithContentToList(fp, seekstart=0, seekend=0, listonly=False, co
2721
2823
  if(len(preheaderdata) == 0):
2722
2824
  break
2723
2825
  prefsize = int(preheaderdata[5], 16)
2724
- prefcompression = preheaderdata[12]
2725
- prefcsize = int(preheaderdata[13], 16)
2726
- prefseeknextfile = HeaderOut[26]
2826
+ if(re.findall("^[.|/]", preheaderdata[5])):
2827
+ prefname = preheaderdata[5]
2828
+ else:
2829
+ prefname = "./"+preheaderdata[5]
2830
+ prefcompression = preheaderdata[14]
2831
+ prefcsize = int(preheaderdata[15], 16)
2832
+ prefseeknextfile = preheaderdata[26]
2727
2833
  prefjsonlen = int(preheaderdata[28], 16)
2728
2834
  prefjsonsize = int(preheaderdata[29], 16)
2729
2835
  prefjsonchecksumtype = preheaderdata[30]
2730
2836
  prefjsonchecksum = preheaderdata[31]
2731
2837
  prefprejsoncontent = fp.read(prefjsonsize).decode("UTF-8")
2732
2838
  fp.seek(len(delimiter), 1)
2733
- prejsonfcs = GetFileChecksum(fprejsoncontent, prefjsonchecksumtype, True, formatspecs)
2839
+ prejsonfcs = GetFileChecksum(prefprejsoncontent, prefjsonchecksumtype, True, formatspecs)
2734
2840
  if(prejsonfcs != prefjsonchecksum and not skipchecksum):
2735
2841
  VerbosePrintOut("File JSON Data Checksum Error with file " +
2736
2842
  prefname + " at offset " + str(prefhstart))
@@ -2817,13 +2923,13 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", seekstart=0, seekend=0,
2817
2923
  fp = UncompressFileAlt(fp, formatspecs)
2818
2924
  checkcompressfile = CheckCompressionSubType(fp, formatspecs, True)
2819
2925
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
2820
- return TarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
2926
+ return TarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
2821
2927
  elif(checkcompressfile == "zipfile" and zipfile.is_zipfile(infile)):
2822
- return ZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
2928
+ return ZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
2823
2929
  elif(rarfile_support and checkcompressfile == "rarfile" and (rarfile.is_rarfile(infile) or rarfile.is_rarfile_sfx(infile))):
2824
- return RarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
2930
+ return RarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
2825
2931
  elif(py7zr_support and checkcompressfile == "7zipfile" and py7zr.is_7zfile(infile)):
2826
- return SevenZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
2932
+ return SevenZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
2827
2933
  elif(IsSingleDict(formatspecs) and checkcompressfile != formatspecs['format_magic']):
2828
2934
  return False
2829
2935
  elif(IsNestedDict(formatspecs) and checkcompressfile not in formatspecs):
@@ -2852,7 +2958,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", seekstart=0, seekend=0,
2852
2958
  return False
2853
2959
  fp.seek(0, 0)
2854
2960
  elif(infile == "-"):
2855
- fp = BytesIO()
2961
+ fp = MkTempFile()
2856
2962
  if(hasattr(sys.stdin, "buffer")):
2857
2963
  shutil.copyfileobj(sys.stdin.buffer, fp)
2858
2964
  else:
@@ -2873,7 +2979,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", seekstart=0, seekend=0,
2873
2979
  return False
2874
2980
  fp.seek(0, 0)
2875
2981
  elif(isinstance(infile, bytes) and sys.version_info[0] >= 3):
2876
- fp = BytesIO()
2982
+ fp = MkTempFile()
2877
2983
  fp.write(infile)
2878
2984
  fp.seek(0, 0)
2879
2985
  fp = UncompressFileAlt(fp, formatspecs)
@@ -2933,13 +3039,13 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", seekstart=0, seekend=0,
2933
3039
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
2934
3040
  formatspecs = formatspecs[checkcompressfile]
2935
3041
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
2936
- return TarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3042
+ return TarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
2937
3043
  elif(checkcompressfile == "zipfile" and zipfile.is_zipfile(infile)):
2938
- return ZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3044
+ return ZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
2939
3045
  elif(rarfile_support and checkcompressfile == "rarfile" and (rarfile.is_rarfile(infile) or rarfile.is_rarfile_sfx(infile))):
2940
- return RarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3046
+ return RarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
2941
3047
  elif(py7zr_support and checkcompressfile == "7zipfile" and py7zr.is_7zfile(infile)):
2942
- return SevenZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3048
+ return SevenZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
2943
3049
  elif(IsSingleDict(formatspecs) and checkcompressfile != formatspecs['format_magic']):
2944
3050
  return False
2945
3051
  elif(IsNestedDict(formatspecs) and checkcompressfile not in formatspecs):
@@ -2978,7 +3084,7 @@ def ReadInMultipleFileWithContentToArray(infile, fmttype="auto", seekstart=0, se
2978
3084
  infile = [infile]
2979
3085
  outretval = {}
2980
3086
  for curfname in infile:
2981
- curretfile = outretval.update({curfname: ReadInFileWithContentToArray(curfname, fmttype, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend)})
3087
+ outretval[curfname] = ReadInFileWithContentToArray(curfname, fmttype, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend)
2982
3088
  return outretval
2983
3089
 
2984
3090
  def ReadInMultipleFilesWithContentToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=False, contentasfile=True, uncompress=True, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False):
@@ -3005,13 +3111,13 @@ def ReadInFileWithContentToList(infile, fmttype="auto", seekstart=0, seekend=0,
3005
3111
  fp = UncompressFileAlt(fp, formatspecs)
3006
3112
  checkcompressfile = CheckCompressionSubType(fp, formatspecs, True)
3007
3113
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
3008
- return TarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
3114
+ return TarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
3009
3115
  elif(checkcompressfile == "zipfile" and zipfile.is_zipfile(infile)):
3010
- return ZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
3116
+ return ZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
3011
3117
  elif(rarfile_support and checkcompressfile == "rarfile" and (rarfile.is_rarfile(infile) or rarfile.is_rarfile_sfx(infile))):
3012
- return RarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
3118
+ return RarFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
3013
3119
  elif(py7zr_support and checkcompressfile == "7zipfile" and py7zr.is_7zfile(infile)):
3014
- return SevenZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, returnfp)
3120
+ return SevenZipFileToArray(infile, seekstart, seekend, listonly, contentasfile, skipchecksum, formatspecs, seektoend, True)
3015
3121
  elif(IsSingleDict(formatspecs) and checkcompressfile != formatspecs['format_magic']):
3016
3122
  return False
3017
3123
  elif(IsNestedDict(formatspecs) and checkcompressfile not in formatspecs):
@@ -3040,7 +3146,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", seekstart=0, seekend=0,
3040
3146
  return False
3041
3147
  fp.seek(0, 0)
3042
3148
  elif(infile == "-"):
3043
- fp = BytesIO()
3149
+ fp = MkTempFile()
3044
3150
  if(hasattr(sys.stdin, "buffer")):
3045
3151
  shutil.copyfileobj(sys.stdin.buffer, fp)
3046
3152
  else:
@@ -3061,7 +3167,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", seekstart=0, seekend=0,
3061
3167
  return False
3062
3168
  fp.seek(0, 0)
3063
3169
  elif(isinstance(infile, bytes) and sys.version_info[0] >= 3):
3064
- fp = BytesIO()
3170
+ fp = MkTempFile()
3065
3171
  fp.write(infile)
3066
3172
  fp.seek(0, 0)
3067
3173
  fp = UncompressFileAlt(fp, formatspecs)
@@ -3121,13 +3227,13 @@ def ReadInFileWithContentToList(infile, fmttype="auto", seekstart=0, seekend=0,
3121
3227
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
3122
3228
  formatspecs = formatspecs[checkcompressfile]
3123
3229
  if(checkcompressfile == "tarfile" and TarFileCheck(infile)):
3124
- return TarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3230
+ return TarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
3125
3231
  elif(checkcompressfile == "zipfile" and zipfile.is_zipfile(infile)):
3126
- return ZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3232
+ return ZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
3127
3233
  elif(rarfile_support and checkcompressfile == "rarfile" and (rarfile.is_rarfile(infile) or rarfile.is_rarfile_sfx(infile))):
3128
- return RarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3234
+ return RarFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
3129
3235
  elif(py7zr_support and checkcompressfile == "7zipfile" and py7zr.is_7zfile(infile)):
3130
- return SevenZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, returnfp)
3236
+ return SevenZipFileToArray(infile, seekstart, seekend, listonly, skipchecksum, formatspecs, seektoend, True)
3131
3237
  elif(IsSingleDict(formatspecs) and checkcompressfile != formatspecs['format_magic']):
3132
3238
  return False
3133
3239
  elif(IsNestedDict(formatspecs) and checkcompressfile not in formatspecs):
@@ -3166,7 +3272,7 @@ def ReadInMultipleFileWithContentToList(infile, fmttype="auto", seekstart=0, see
3166
3272
  infile = [infile]
3167
3273
  outretval = {}
3168
3274
  for curfname in infile:
3169
- curretfile = outretval.update({curfname: ReadInFileWithContentToList(curfname, fmttype, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend)})
3275
+ curretfile[curfname] = ReadInFileWithContentToList(curfname, fmttype, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend)
3170
3276
  return outretval
3171
3277
 
3172
3278
  def ReadInMultipleFilesWithContentToList(infile, fmttype="auto", seekstart=0, seekend=0, listonly=False, contentasfile=True, uncompress=True, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False):
@@ -3211,7 +3317,7 @@ def AppendFileHeader(fp, numfiles, fencoding, extradata=[], checksumtype="crc32"
3211
3317
  tmpoutlist = []
3212
3318
  tmpoutlist.append(extrasizelen)
3213
3319
  tmpoutlist.append(extrafields)
3214
- fnumfiles = format(int(numfiles), 'x').lower()
3320
+ fnumfiles = format(numfiles, 'x').lower()
3215
3321
  tmpoutlen = 3 + len(tmpoutlist) + len(extradata) + 2
3216
3322
  tmpoutlenhex = format(tmpoutlen, 'x').lower()
3217
3323
  fnumfilesa = AppendNullBytes(
@@ -3269,7 +3375,7 @@ def MakeEmptyFoxFilePointer(fp, fmttype=__file_format_default__, checksumtype="c
3269
3375
  return MakeEmptyFilePointer(fp, fmttype, checksumtype, formatspecs)
3270
3376
 
3271
3377
 
3272
- def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", formatspecs=__file_format_multi_dict__, returnfp=False):
3378
+ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile=True, compressionlevel=None, compressionuselist=compressionlistalt, checksumtype="crc32", formatspecs=__file_format_multi_dict__, returnfp=False):
3273
3379
  if(IsNestedDict(formatspecs) and fmttype=="auto" and
3274
3380
  (outfile != "-" and outfile is not None and not hasattr(outfile, "read") and not hasattr(outfile, "write"))):
3275
3381
  get_in_ext = os.path.splitext(outfile)
@@ -3296,11 +3402,11 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
3296
3402
  pass
3297
3403
  if(outfile == "-" or outfile is None):
3298
3404
  verbose = False
3299
- fp = BytesIO()
3405
+ fp = MkTempFile()
3300
3406
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
3301
3407
  fp = outfile
3302
3408
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3303
- fp = BytesIO()
3409
+ fp = MkTempFile()
3304
3410
  else:
3305
3411
  fbasename = os.path.splitext(outfile)[0]
3306
3412
  fextname = os.path.splitext(outfile)[1]
@@ -3313,7 +3419,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
3313
3419
  AppendFileHeader(fp, 0, "UTF-8", [], checksumtype, formatspecs)
3314
3420
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
3315
3421
  fp = CompressOpenFileAlt(
3316
- fp, compression, compressionlevel, formatspecs)
3422
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
3317
3423
  try:
3318
3424
  fp.flush()
3319
3425
  if(hasattr(os, "sync")):
@@ -3337,7 +3443,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
3337
3443
  return outvar
3338
3444
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3339
3445
  fp = CompressOpenFileAlt(
3340
- fp, compression, compressionlevel, formatspecs)
3446
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
3341
3447
  fp.seek(0, 0)
3342
3448
  upload_file_to_internet_file(fp, outfile)
3343
3449
  if(returnfp):
@@ -3348,8 +3454,8 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
3348
3454
  return True
3349
3455
 
3350
3456
 
3351
- def MakeEmptyFoxFile(outfile, compression="auto", compresswholefile=True, compressionlevel=None, checksumtype="crc32", formatspecs=__file_format_dict__, returnfp=False):
3352
- return MakeEmptyFile(outfile, compression, compresswholefile, compressionlevel, checksumtype, formatspecs, returnfp)
3457
+ def MakeEmptyFoxFile(outfile, compression="auto", compresswholefile=True, compressionlevel=None, compressionuselist=compressionlistalt, checksumtype="crc32", formatspecs=__file_format_dict__, returnfp=False):
3458
+ return MakeEmptyFile(outfile, "auto", compression, compresswholefile, compressionlevel, compressionuselist, checksumtype, formatspecs, returnfp)
3353
3459
 
3354
3460
 
3355
3461
  def AppendFileHeaderWithContent(fp, filevalues=[], extradata=[], jsondata={}, filecontent="", checksumtype=["crc32", "crc32", "crc32"], formatspecs=__file_format_dict__):
@@ -3448,6 +3554,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3448
3554
  if(verbose):
3449
3555
  logging.basicConfig(format="%(message)s",
3450
3556
  stream=sys.stdout, level=logging.DEBUG)
3557
+ infilelist = []
3451
3558
  if(infiles == "-"):
3452
3559
  for line in sys.stdin:
3453
3560
  infilelist.append(line.strip())
@@ -3488,7 +3595,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3488
3595
  inodetoforminode = {}
3489
3596
  numfiles = int(len(GetDirList))
3490
3597
  fnumfiles = format(numfiles, 'x').lower()
3491
- AppendFileHeader(fp, fnumfiles, "UTF-8", [], checksumtype[0], formatspecs)
3598
+ AppendFileHeader(fp, numfiles, "UTF-8", [], checksumtype[0], formatspecs)
3492
3599
  FullSizeFilesAlt = 0
3493
3600
  for curfname in GetDirList:
3494
3601
  fencoding = "UTF-8"
@@ -3586,7 +3693,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3586
3693
  elif ftype in data_types:
3587
3694
  fsize = format(int(fstatinfo.st_size), 'x').lower()
3588
3695
  else:
3589
- fsize = format(int(fstatinfo.st_size)).lower()
3696
+ fsize = format(int(fstatinfo.st_size), 'x').lower()
3590
3697
  fatime = format(int(fstatinfo.st_atime), 'x').lower()
3591
3698
  fmtime = format(int(fstatinfo.st_mtime), 'x').lower()
3592
3699
  fctime = format(int(fstatinfo.st_ctime), 'x').lower()
@@ -3631,7 +3738,7 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3631
3738
  fwinattributes = format(int(0), 'x').lower()
3632
3739
  fcompression = ""
3633
3740
  fcsize = format(int(0), 'x').lower()
3634
- fcontents = BytesIO()
3741
+ fcontents = MkTempFile()
3635
3742
  chunk_size = 1024
3636
3743
  fcencoding = "UTF-8"
3637
3744
  curcompression = "none"
@@ -3650,13 +3757,13 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3650
3757
  ilmin = 0
3651
3758
  ilcsize = []
3652
3759
  while(ilmin < ilsize):
3653
- cfcontents = BytesIO()
3760
+ cfcontents = MkTempFile()
3654
3761
  fcontents.seek(0, 0)
3655
3762
  shutil.copyfileobj(fcontents, cfcontents)
3656
3763
  fcontents.seek(0, 0)
3657
3764
  cfcontents.seek(0, 0)
3658
3765
  cfcontents = CompressOpenFileAlt(
3659
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
3766
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
3660
3767
  if(cfcontents):
3661
3768
  cfcontents.seek(0, 2)
3662
3769
  ilcsize.append(cfcontents.tell())
@@ -3667,11 +3774,11 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3667
3774
  ilcmin = ilcsize.index(min(ilcsize))
3668
3775
  curcompression = compressionuselist[ilcmin]
3669
3776
  fcontents.seek(0, 0)
3670
- cfcontents = BytesIO()
3777
+ cfcontents = MkTempFile()
3671
3778
  shutil.copyfileobj(fcontents, cfcontents)
3672
3779
  cfcontents.seek(0, 0)
3673
3780
  cfcontents = CompressOpenFileAlt(
3674
- cfcontents, curcompression, compressionlevel, formatspecs)
3781
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
3675
3782
  cfcontents.seek(0, 2)
3676
3783
  cfsize = cfcontents.tell()
3677
3784
  if(ucfsize > cfsize):
@@ -3697,13 +3804,13 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3697
3804
  ilmin = 0
3698
3805
  ilcsize = []
3699
3806
  while(ilmin < ilsize):
3700
- cfcontents = BytesIO()
3807
+ cfcontents = MkTempFile()
3701
3808
  fcontents.seek(0, 0)
3702
3809
  shutil.copyfileobj(fcontents, cfcontents)
3703
3810
  fcontents.seek(0, 0)
3704
3811
  cfcontents.seek(0, 0)
3705
3812
  cfcontents = CompressOpenFileAlt(
3706
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
3813
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
3707
3814
  if(cfcontents):
3708
3815
  cfcontents.seek(0, 2)
3709
3816
  ilcsize.append(cfcontents.tell())
@@ -3714,11 +3821,11 @@ def AppendFilesWithContent(infiles, fp, dirlistfromtxt=False, filevalues=[], ext
3714
3821
  ilcmin = ilcsize.index(min(ilcsize))
3715
3822
  curcompression = compressionuselist[ilcmin]
3716
3823
  fcontents.seek(0, 0)
3717
- cfcontents = BytesIO()
3824
+ cfcontents = MkTempFile()
3718
3825
  shutil.copyfileobj(fcontents, cfcontents)
3719
3826
  cfcontents.seek(0, 0)
3720
3827
  cfcontents = CompressOpenFileAlt(
3721
- cfcontents, curcompression, compressionlevel, formatspecs)
3828
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
3722
3829
  cfcontents.seek(0, 2)
3723
3830
  cfsize = cfcontents.tell()
3724
3831
  if(ucfsize > cfsize):
@@ -3760,7 +3867,7 @@ def AppendListsWithContent(inlist, fp, dirlistfromtxt=False, filevalues=[], extr
3760
3867
  inodetoforminode = {}
3761
3868
  numfiles = int(len(GetDirList))
3762
3869
  fnumfiles = format(numfiles, 'x').lower()
3763
- AppendFileHeader(fp, fnumfiles, "UTF-8", [], checksumtype[0], formatspecs)
3870
+ AppendFileHeader(fp, numfiles, "UTF-8", [], checksumtype[0], formatspecs)
3764
3871
  for curfname in GetDirList:
3765
3872
  ftype = format(curfname[0], 'x').lower()
3766
3873
  fencoding = curfname[1]
@@ -3844,11 +3951,11 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
3844
3951
  pass
3845
3952
  if(outfile == "-" or outfile is None):
3846
3953
  verbose = False
3847
- fp = BytesIO()
3954
+ fp = MkTempFile()
3848
3955
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
3849
3956
  fp = outfile
3850
3957
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3851
- fp = BytesIO()
3958
+ fp = MkTempFile()
3852
3959
  else:
3853
3960
  fbasename = os.path.splitext(outfile)[0]
3854
3961
  fextname = os.path.splitext(outfile)[1]
@@ -3862,7 +3969,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
3862
3969
  compresswholefile, compressionlevel, compressionuselist, followlink, checksumtype, formatspecs, verbose)
3863
3970
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
3864
3971
  fp = CompressOpenFileAlt(
3865
- fp, compression, compressionlevel, formatspecs)
3972
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
3866
3973
  try:
3867
3974
  fp.flush()
3868
3975
  if(hasattr(os, "sync")):
@@ -3886,7 +3993,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
3886
3993
  return outvar
3887
3994
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3888
3995
  fp = CompressOpenFileAlt(
3889
- fp, compression, compressionlevel, formatspecs)
3996
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
3890
3997
  fp.seek(0, 0)
3891
3998
  upload_file_to_internet_file(fp, outfile)
3892
3999
  if(returnfp):
@@ -3924,11 +4031,11 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
3924
4031
  pass
3925
4032
  if(outfile == "-" or outfile is None):
3926
4033
  verbose = False
3927
- fp = BytesIO()
4034
+ fp = MkTempFile()
3928
4035
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
3929
4036
  fp = outfile
3930
4037
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3931
- fp = BytesIO()
4038
+ fp = MkTempFile()
3932
4039
  else:
3933
4040
  fbasename = os.path.splitext(outfile)[0]
3934
4041
  fextname = os.path.splitext(outfile)[1]
@@ -3942,7 +4049,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
3942
4049
  compresswholefile, compressionlevel, followlink, checksumtype, formatspecs, verbose)
3943
4050
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
3944
4051
  fp = CompressOpenFileAlt(
3945
- fp, compression, compressionlevel, formatspecs)
4052
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
3946
4053
  try:
3947
4054
  fp.flush()
3948
4055
  if(hasattr(os, "sync")):
@@ -3966,7 +4073,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
3966
4073
  return outvar
3967
4074
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3968
4075
  fp = CompressOpenFileAlt(
3969
- fp, compression, compressionlevel, formatspecs)
4076
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
3970
4077
  fp.seek(0, 0)
3971
4078
  upload_file_to_internet_file(fp, outfile)
3972
4079
  if(returnfp):
@@ -4045,7 +4152,7 @@ def GzipCompressData(data, compresslevel=9):
4045
4152
  compressed_data = gzip.compress(data, compresslevel=compresslevel)
4046
4153
  except AttributeError:
4047
4154
  # Fallback to older method for Python 2.x and older 3.x versions
4048
- out = BytesIO()
4155
+ out = MkTempFile()
4049
4156
  with gzip.GzipFile(fileobj=out, mode="wb", compresslevel=compresslevel) as f:
4050
4157
  f.write(data)
4051
4158
  compressed_data = out.getvalue()
@@ -4058,7 +4165,7 @@ def GzipDecompressData(compressed_data):
4058
4165
  decompressed_data = gzip.decompress(compressed_data)
4059
4166
  except AttributeError:
4060
4167
  # Fallback to older method for Python 2.x and older 3.x versions
4061
- inp = BytesIO(compressed_data)
4168
+ inp = MkTempFile(compressed_data)
4062
4169
  with gzip.GzipFile(fileobj=inp, mode="rb") as f:
4063
4170
  decompressed_data = f.read()
4064
4171
  return decompressed_data
@@ -4191,9 +4298,9 @@ def GetFileEncoding(infile, closefp=True):
4191
4298
 
4192
4299
  def GetFileEncodingFromString(instring, closefp=True):
4193
4300
  try:
4194
- instringsfile = BytesIO(instring)
4301
+ instringsfile = MkTempFile(instring)
4195
4302
  except TypeError:
4196
- instringsfile = BytesIO(instring.encode("UTF-8"))
4303
+ instringsfile = MkTempFile(instring.encode("UTF-8"))
4197
4304
  return GetFileEncoding(instringsfile, closefp)
4198
4305
 
4199
4306
 
@@ -4456,17 +4563,17 @@ def CheckCompressionSubType(infile, formatspecs=__file_format_multi_dict__, clos
4456
4563
 
4457
4564
  def CheckCompressionTypeFromString(instring, formatspecs=__file_format_multi_dict__, closefp=True):
4458
4565
  try:
4459
- instringsfile = BytesIO(instring)
4566
+ instringsfile = MkTempFile(instring)
4460
4567
  except TypeError:
4461
- instringsfile = BytesIO(instring.encode("UTF-8"))
4568
+ instringsfile = MkTempFile(instring.encode("UTF-8"))
4462
4569
  return CheckCompressionType(instringsfile, formatspecs, closefp)
4463
4570
 
4464
4571
 
4465
4572
  def CheckCompressionTypeFromBytes(instring, formatspecs=__file_format_multi_dict__, closefp=True):
4466
4573
  try:
4467
- instringsfile = BytesIO(instring)
4574
+ instringsfile = MkTempFile(instring)
4468
4575
  except TypeError:
4469
- instringsfile = BytesIO(instring.decode("UTF-8"))
4576
+ instringsfile = MkTempFile(instring.decode("UTF-8"))
4470
4577
  return CheckCompressionType(instringsfile, formatspecs, closefp)
4471
4578
 
4472
4579
 
@@ -4633,7 +4740,7 @@ def UncompressBytes(infile, formatspecs=__file_format_multi_dict__):
4633
4740
 
4634
4741
 
4635
4742
  def UncompressBytesAlt(inbytes, formatspecs=__file_format_multi_dict__):
4636
- filefp = BytesIO()
4743
+ filefp = MkTempFile()
4637
4744
  outstring = UncompressBytes(inbytes, formatspecs)
4638
4745
  filefp.write(outstring)
4639
4746
  filefp.seek(0, 0)
@@ -4649,7 +4756,7 @@ def UncompressBytesAltFP(fp, formatspecs=__file_format_multi_dict__):
4649
4756
  fp.seek(0, 0)
4650
4757
  if(prechck!="zstd"):
4651
4758
  return UncompressFileAlt(fp, formatspecs)
4652
- filefp = BytesIO()
4759
+ filefp = MkTempFile()
4653
4760
  fp.seek(0, 0)
4654
4761
  outstring = UncompressBytes(fp.read(), formatspecs)
4655
4762
  filefp.write(outstring)
@@ -4657,16 +4764,16 @@ def UncompressBytesAltFP(fp, formatspecs=__file_format_multi_dict__):
4657
4764
  return filefp
4658
4765
 
4659
4766
 
4660
- def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspecs=__file_format_dict__):
4767
+ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, compressionuselist=compressionlistalt, formatspecs=__file_format_dict__):
4661
4768
  if(not hasattr(fp, "read")):
4662
4769
  return False
4663
4770
  fp.seek(0, 0)
4664
4771
  if(not compression or compression == formatspecs['format_magic']):
4665
4772
  compression = "auto"
4666
- if(compression not in compressionlist and compression is None):
4773
+ if(compression not in compressionuselist and compression is None):
4667
4774
  compression = "auto"
4668
4775
  if(compression == "gzip" and compression in compressionsupport):
4669
- bytesfp = BytesIO()
4776
+ bytesfp = MkTempFile()
4670
4777
  if(compressionlevel is None):
4671
4778
  compressionlevel = 9
4672
4779
  else:
@@ -4674,7 +4781,7 @@ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspe
4674
4781
  bytesfp.write(GzipCompressData(
4675
4782
  fp.read(), compresslevel=compressionlevel))
4676
4783
  elif(compression == "bzip2" and compression in compressionsupport):
4677
- bytesfp = BytesIO()
4784
+ bytesfp = MkTempFile()
4678
4785
  if(compressionlevel is None):
4679
4786
  compressionlevel = 9
4680
4787
  else:
@@ -4682,7 +4789,7 @@ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspe
4682
4789
  bytesfp.write(BzipCompressData(
4683
4790
  fp.read(), compresslevel=compressionlevel))
4684
4791
  elif(compression == "lz4" and compression in compressionsupport):
4685
- bytesfp = BytesIO()
4792
+ bytesfp = MkTempFile()
4686
4793
  if(compressionlevel is None):
4687
4794
  compressionlevel = 9
4688
4795
  else:
@@ -4690,14 +4797,14 @@ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspe
4690
4797
  bytesfp.write(lz4.frame.compress(
4691
4798
  fp.read(), compression_level=compressionlevel))
4692
4799
  elif((compression == "lzo" or compression == "lzop") and compression in compressionsupport):
4693
- bytesfp = BytesIO()
4800
+ bytesfp = MkTempFile()
4694
4801
  if(compressionlevel is None):
4695
4802
  compressionlevel = 9
4696
4803
  else:
4697
4804
  compressionlevel = int(compressionlevel)
4698
4805
  bytesfp.write(lzo.compress(fp.read(), compressionlevel))
4699
4806
  elif(compression == "zstd" and compression in compressionsupport):
4700
- bytesfp = BytesIO()
4807
+ bytesfp = MkTempFile()
4701
4808
  if(compressionlevel is None):
4702
4809
  compressionlevel = 9
4703
4810
  else:
@@ -4705,7 +4812,7 @@ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspe
4705
4812
  compressor = zstandard.ZstdCompressor(compressionlevel, threads=get_default_threads())
4706
4813
  bytesfp.write(compressor.compress(fp.read()))
4707
4814
  elif(compression == "lzma" and compression in compressionsupport):
4708
- bytesfp = BytesIO()
4815
+ bytesfp = MkTempFile()
4709
4816
  if(compressionlevel is None):
4710
4817
  compressionlevel = 9
4711
4818
  else:
@@ -4715,7 +4822,7 @@ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspe
4715
4822
  except (NotImplementedError, lzma.LZMAError):
4716
4823
  bytesfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_ALONE))
4717
4824
  elif(compression == "xz" and compression in compressionsupport):
4718
- bytesfp = BytesIO()
4825
+ bytesfp = MkTempFile()
4719
4826
  if(compressionlevel is None):
4720
4827
  compressionlevel = 9
4721
4828
  else:
@@ -4725,7 +4832,7 @@ def CompressOpenFileAlt(fp, compression="auto", compressionlevel=None, formatspe
4725
4832
  except (NotImplementedError, lzma.LZMAError):
4726
4833
  bytesfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_XZ))
4727
4834
  elif(compression == "zlib" and compression in compressionsupport):
4728
- bytesfp = BytesIO()
4835
+ bytesfp = MkTempFile()
4729
4836
  if(compressionlevel is None):
4730
4837
  compressionlevel = 9
4731
4838
  else:
@@ -4882,7 +4989,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
4882
4989
  outfile = RemoveWindowsPath(outfile)
4883
4990
  if(not compression or compression == formatspecs['format_magic']):
4884
4991
  compression = "auto"
4885
- if(compression not in compressionlist and compression is None):
4992
+ if(compression not in compressionuselist and compression is None):
4886
4993
  compression = "auto"
4887
4994
  if(verbose):
4888
4995
  logging.basicConfig(format="%(message)s",
@@ -4895,11 +5002,11 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
4895
5002
  pass
4896
5003
  if(outfile == "-" or outfile is None):
4897
5004
  verbose = False
4898
- fp = BytesIO()
5005
+ fp = MkTempFile()
4899
5006
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
4900
5007
  fp = outfile
4901
5008
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
4902
- fp = BytesIO()
5009
+ fp = MkTempFile()
4903
5010
  else:
4904
5011
  fbasename = os.path.splitext(outfile)[0]
4905
5012
  fextname = os.path.splitext(outfile)[1]
@@ -5049,7 +5156,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5049
5156
  elif ftype in data_types:
5050
5157
  fsize = format(int(fstatinfo.st_size), 'x').lower()
5051
5158
  else:
5052
- fsize = format(int(fstatinfo.st_size)).lower()
5159
+ fsize = format(int(fstatinfo.st_size), 'x').lower()
5053
5160
  fatime = format(int(fstatinfo.st_atime), 'x').lower()
5054
5161
  fmtime = format(int(fstatinfo.st_mtime), 'x').lower()
5055
5162
  fctime = format(int(fstatinfo.st_ctime), 'x').lower()
@@ -5094,7 +5201,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5094
5201
  fwinattributes = format(int(0), 'x').lower()
5095
5202
  fcompression = ""
5096
5203
  fcsize = format(int(0), 'x').lower()
5097
- fcontents = BytesIO()
5204
+ fcontents = MkTempFile()
5098
5205
  fcencoding = "UTF-8"
5099
5206
  curcompression = "none"
5100
5207
  if not followlink and ftype in data_types:
@@ -5112,13 +5219,13 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5112
5219
  ilmin = 0
5113
5220
  ilcsize = []
5114
5221
  while(ilmin < ilsize):
5115
- cfcontents = BytesIO()
5222
+ cfcontents = MkTempFile()
5116
5223
  fcontents.seek(0, 0)
5117
5224
  shutil.copyfileobj(fcontents, cfcontents)
5118
5225
  fcontents.seek(0, 0)
5119
5226
  cfcontents.seek(0, 0)
5120
5227
  cfcontents = CompressOpenFileAlt(
5121
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
5228
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
5122
5229
  if(cfcontents):
5123
5230
  cfcontents.seek(0, 2)
5124
5231
  ilcsize.append(cfcontents.tell())
@@ -5129,11 +5236,11 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5129
5236
  ilcmin = ilcsize.index(min(ilcsize))
5130
5237
  curcompression = compressionuselist[ilcmin]
5131
5238
  fcontents.seek(0, 0)
5132
- cfcontents = BytesIO()
5239
+ cfcontents = MkTempFile()
5133
5240
  shutil.copyfileobj(fcontents, cfcontents)
5134
5241
  cfcontents.seek(0, 0)
5135
5242
  cfcontents = CompressOpenFileAlt(
5136
- cfcontents, curcompression, compressionlevel, formatspecs)
5243
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
5137
5244
  cfcontents.seek(0, 2)
5138
5245
  cfsize = cfcontents.tell()
5139
5246
  if(ucfsize > cfsize):
@@ -5159,13 +5266,13 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5159
5266
  ilmin = 0
5160
5267
  ilcsize = []
5161
5268
  while(ilmin < ilsize):
5162
- cfcontents = BytesIO()
5269
+ cfcontents = MkTempFile()
5163
5270
  fcontents.seek(0, 0)
5164
5271
  shutil.copyfileobj(fcontents, cfcontents)
5165
5272
  fcontents.seek(0, 0)
5166
5273
  cfcontents.seek(0, 0)
5167
5274
  cfcontents = CompressOpenFileAlt(
5168
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
5275
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
5169
5276
  if(cfcontents):
5170
5277
  cfcontents.seek(0, 2)
5171
5278
  ilcsize.append(cfcontents.tell())
@@ -5176,11 +5283,11 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5176
5283
  ilcmin = ilcsize.index(min(ilcsize))
5177
5284
  curcompression = compressionuselist[ilcmin]
5178
5285
  fcontents.seek(0, 0)
5179
- cfcontents = BytesIO()
5286
+ cfcontents = MkTempFile()
5180
5287
  shutil.copyfileobj(fcontents, cfcontents)
5181
5288
  cfcontents.seek(0, 0)
5182
5289
  cfcontents = CompressOpenFileAlt(
5183
- cfcontents, curcompression, compressionlevel, formatspecs)
5290
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
5184
5291
  cfcontents.seek(0, 2)
5185
5292
  cfsize = cfcontents.tell()
5186
5293
  if(ucfsize > cfsize):
@@ -5205,7 +5312,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5205
5312
  return False
5206
5313
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
5207
5314
  fp = CompressOpenFileAlt(
5208
- fp, compression, compressionlevel, formatspecs)
5315
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
5209
5316
  try:
5210
5317
  fp.flush()
5211
5318
  if(hasattr(os, "sync")):
@@ -5229,7 +5336,7 @@ def PackFoxFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
5229
5336
  return outvar
5230
5337
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5231
5338
  fp = CompressOpenFileAlt(
5232
- fp, compression, compressionlevel, formatspecs)
5339
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
5233
5340
  fp.seek(0, 0)
5234
5341
  upload_file_to_internet_file(fp, outfile)
5235
5342
  if(returnfp):
@@ -5267,7 +5374,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5267
5374
  outfile = RemoveWindowsPath(outfile)
5268
5375
  if(not compression or compression == formatspecs['format_magic']):
5269
5376
  compression = "auto"
5270
- if(compression not in compressionlist and compression is None):
5377
+ if(compression not in compressionuselist and compression is None):
5271
5378
  compression = "auto"
5272
5379
  if(verbose):
5273
5380
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
@@ -5279,11 +5386,11 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5279
5386
  pass
5280
5387
  if(outfile == "-" or outfile is None):
5281
5388
  verbose = False
5282
- fp = BytesIO()
5389
+ fp = MkTempFile()
5283
5390
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
5284
5391
  fp = outfile
5285
5392
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5286
- fp = BytesIO()
5393
+ fp = MkTempFile()
5287
5394
  else:
5288
5395
  fbasename = os.path.splitext(outfile)[0]
5289
5396
  fextname = os.path.splitext(outfile)[1]
@@ -5302,7 +5409,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5302
5409
  filetoinode = {}
5303
5410
  inodetoforminode = {}
5304
5411
  if(infile == "-"):
5305
- infile = BytesIO()
5412
+ infile = MkTempFile()
5306
5413
  if(hasattr(sys.stdin, "buffer")):
5307
5414
  shutil.copyfileobj(sys.stdin.buffer, infile)
5308
5415
  else:
@@ -5342,7 +5449,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5342
5449
  if 'zstandard' in sys.modules:
5343
5450
  infile = ZstdFile(fileobj=infile, mode="rb")
5344
5451
  elif 'pyzstd' in sys.modules:
5345
- fp = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
5452
+ infile = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
5346
5453
  tarfp = tarfile.open(fileobj=infile, mode="r")
5347
5454
  else:
5348
5455
  tarfp = tarfile.open(fileobj=infile, mode="r")
@@ -5354,7 +5461,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5354
5461
  if 'zstandard' in sys.modules:
5355
5462
  infile = ZstdFile(fileobj=infile, mode="rb")
5356
5463
  elif 'pyzstd' in sys.modules:
5357
- fp = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
5464
+ infile = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
5358
5465
  tarfp = tarfile.open(fileobj=infile, mode="r")
5359
5466
  else:
5360
5467
  tarfp = tarfile.open(infile, "r")
@@ -5441,12 +5548,13 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5441
5548
  fwinattributes = format(int(0), 'x').lower()
5442
5549
  fcompression = ""
5443
5550
  fcsize = format(int(0), 'x').lower()
5444
- fcontents = BytesIO()
5551
+ fcontents = MkTempFile()
5445
5552
  fcencoding = "UTF-8"
5446
5553
  curcompression = "none"
5447
5554
  if ftype in data_types:
5448
5555
  fpc = tarfp.extractfile(member)
5449
5556
  shutil.copyfileobj(fpc, fcontents)
5557
+ fpc.close()
5450
5558
  typechecktest = CheckCompressionType(fcontents, closefp=False)
5451
5559
  fcontents.seek(0, 0)
5452
5560
  fcencoding = GetFileEncoding(fcontents, False)
@@ -5459,13 +5567,13 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5459
5567
  ilmin = 0
5460
5568
  ilcsize = []
5461
5569
  while(ilmin < ilsize):
5462
- cfcontents = BytesIO()
5570
+ cfcontents = MkTempFile()
5463
5571
  fcontents.seek(0, 0)
5464
5572
  shutil.copyfileobj(fcontents, cfcontents)
5465
5573
  fcontents.seek(0, 0)
5466
5574
  cfcontents.seek(0, 0)
5467
5575
  cfcontents = CompressOpenFileAlt(
5468
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
5576
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
5469
5577
  if(cfcontents):
5470
5578
  cfcontents.seek(0, 2)
5471
5579
  ilcsize.append(cfcontents.tell())
@@ -5476,11 +5584,11 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5476
5584
  ilcmin = ilcsize.index(min(ilcsize))
5477
5585
  curcompression = compressionuselist[ilcmin]
5478
5586
  fcontents.seek(0, 0)
5479
- cfcontents = BytesIO()
5587
+ cfcontents = MkTempFile()
5480
5588
  shutil.copyfileobj(fcontents, cfcontents)
5481
5589
  cfcontents.seek(0, 0)
5482
5590
  cfcontents = CompressOpenFileAlt(
5483
- cfcontents, curcompression, compressionlevel, formatspecs)
5591
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
5484
5592
  cfcontents.seek(0, 2)
5485
5593
  cfsize = cfcontents.tell()
5486
5594
  if(ucfsize > cfsize):
@@ -5505,7 +5613,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5505
5613
  return False
5506
5614
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
5507
5615
  fp = CompressOpenFileAlt(
5508
- fp, compression, compressionlevel, formatspecs)
5616
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
5509
5617
  try:
5510
5618
  fp.flush()
5511
5619
  if(hasattr(os, "sync")):
@@ -5529,7 +5637,7 @@ def PackFoxFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
5529
5637
  return outvar
5530
5638
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5531
5639
  fp = CompressOpenFileAlt(
5532
- fp, compression, compressionlevel, formatspecs)
5640
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
5533
5641
  fp.seek(0, 0)
5534
5642
  upload_file_to_internet_file(fp, outfile)
5535
5643
  if(returnfp):
@@ -5563,7 +5671,7 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5563
5671
  outfile = RemoveWindowsPath(outfile)
5564
5672
  if(not compression or compression == formatspecs['format_magic']):
5565
5673
  compression = "auto"
5566
- if(compression not in compressionlist and compression is None):
5674
+ if(compression not in compressionuselist and compression is None):
5567
5675
  compression = "auto"
5568
5676
  if(verbose):
5569
5677
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
@@ -5575,11 +5683,11 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5575
5683
  pass
5576
5684
  if(outfile == "-" or outfile is None):
5577
5685
  verbose = False
5578
- fp = BytesIO()
5686
+ fp = MkTempFile()
5579
5687
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
5580
5688
  fp = outfile
5581
5689
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5582
- fp = BytesIO()
5690
+ fp = MkTempFile()
5583
5691
  else:
5584
5692
  fbasename = os.path.splitext(outfile)[0]
5585
5693
  fextname = os.path.splitext(outfile)[1]
@@ -5598,7 +5706,7 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5598
5706
  filetoinode = {}
5599
5707
  inodetoforminode = {}
5600
5708
  if(infile == "-"):
5601
- infile = BytesIO()
5709
+ infile = MkTempFile()
5602
5710
  if(hasattr(sys.stdin, "buffer")):
5603
5711
  shutil.copyfileobj(sys.stdin.buffer, infile)
5604
5712
  else:
@@ -5739,7 +5847,7 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5739
5847
  fgname = ""
5740
5848
  except ImportError:
5741
5849
  fgname = ""
5742
- fcontents = BytesIO()
5850
+ fcontents = MkTempFile()
5743
5851
  fcencoding = "UTF-8"
5744
5852
  curcompression = "none"
5745
5853
  if ftype == 0:
@@ -5756,13 +5864,13 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5756
5864
  ilmin = 0
5757
5865
  ilcsize = []
5758
5866
  while(ilmin < ilsize):
5759
- cfcontents = BytesIO()
5867
+ cfcontents = MkTempFile()
5760
5868
  fcontents.seek(0, 0)
5761
5869
  shutil.copyfileobj(fcontents, cfcontents)
5762
5870
  fcontents.seek(0, 0)
5763
5871
  cfcontents.seek(0, 0)
5764
5872
  cfcontents = CompressOpenFileAlt(
5765
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
5873
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
5766
5874
  cfcontents.seek(0, 2)
5767
5875
  ilcsize.append(cfcontents.tell())
5768
5876
  cfcontents.close()
@@ -5770,11 +5878,11 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5770
5878
  ilcmin = ilcsize.index(min(ilcsize))
5771
5879
  curcompression = compressionuselist[ilcmin]
5772
5880
  fcontents.seek(0, 0)
5773
- cfcontents = BytesIO()
5881
+ cfcontents = MkTempFile()
5774
5882
  shutil.copyfileobj(fcontents, cfcontents)
5775
5883
  cfcontents.seek(0, 0)
5776
5884
  cfcontents = CompressOpenFileAlt(
5777
- cfcontents, curcompression, compressionlevel, formatspecs)
5885
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
5778
5886
  cfcontents.seek(0, 2)
5779
5887
  cfsize = cfcontents.tell()
5780
5888
  if(ucfsize > cfsize):
@@ -5799,7 +5907,7 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5799
5907
  return False
5800
5908
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
5801
5909
  fp = CompressOpenFileAlt(
5802
- fp, compression, compressionlevel, formatspecs)
5910
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
5803
5911
  try:
5804
5912
  fp.flush()
5805
5913
  if(hasattr(os, "sync")):
@@ -5823,7 +5931,7 @@ def PackFoxFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
5823
5931
  return outvar
5824
5932
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5825
5933
  fp = CompressOpenFileAlt(
5826
- fp, compression, compressionlevel, formatspecs)
5934
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
5827
5935
  fp.seek(0, 0)
5828
5936
  upload_file_to_internet_file(fp, outfile)
5829
5937
  if(returnfp):
@@ -5862,7 +5970,7 @@ if(rarfile_support):
5862
5970
  outfile = RemoveWindowsPath(outfile)
5863
5971
  if(not compression or compression == formatspecs['format_magic']):
5864
5972
  compression = "auto"
5865
- if(compression not in compressionlist and compression is None):
5973
+ if(compression not in compressionuselist and compression is None):
5866
5974
  compression = "auto"
5867
5975
  if(verbose):
5868
5976
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
@@ -5874,11 +5982,11 @@ if(rarfile_support):
5874
5982
  pass
5875
5983
  if(outfile == "-" or outfile is None):
5876
5984
  verbose = False
5877
- fp = BytesIO()
5985
+ fp = MkTempFile()
5878
5986
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
5879
5987
  fp = outfile
5880
5988
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5881
- fp = BytesIO()
5989
+ fp = MkTempFile()
5882
5990
  else:
5883
5991
  fbasename = os.path.splitext(outfile)[0]
5884
5992
  fextname = os.path.splitext(outfile)[1]
@@ -6056,7 +6164,7 @@ if(rarfile_support):
6056
6164
  fgname = ""
6057
6165
  except ImportError:
6058
6166
  fgname = ""
6059
- fcontents = BytesIO()
6167
+ fcontents = MkTempFile()
6060
6168
  fcencoding = "UTF-8"
6061
6169
  curcompression = "none"
6062
6170
  if ftype == 0:
@@ -6073,13 +6181,13 @@ if(rarfile_support):
6073
6181
  ilmin = 0
6074
6182
  ilcsize = []
6075
6183
  while(ilmin < ilsize):
6076
- cfcontents = BytesIO()
6184
+ cfcontents = MkTempFile()
6077
6185
  fcontents.seek(0, 0)
6078
6186
  shutil.copyfileobj(fcontents, cfcontents)
6079
6187
  fcontents.seek(0, 0)
6080
6188
  cfcontents.seek(0, 0)
6081
6189
  cfcontents = CompressOpenFileAlt(
6082
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
6190
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
6083
6191
  if(cfcontents):
6084
6192
  cfcontents.seek(0, 2)
6085
6193
  ilcsize.append(cfcontents.tell())
@@ -6090,16 +6198,16 @@ if(rarfile_support):
6090
6198
  ilcmin = ilcsize.index(min(ilcsize))
6091
6199
  curcompression = compressionuselist[ilcmin]
6092
6200
  fcontents.seek(0, 0)
6093
- cfcontents = BytesIO()
6201
+ cfcontents = MkTempFile()
6094
6202
  shutil.copyfileobj(fcontents, cfcontents)
6095
6203
  cfcontents.seek(0, 0)
6096
6204
  cfcontents = CompressOpenFileAlt(
6097
- cfcontents, curcompression, compressionlevel, formatspecs)
6205
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
6098
6206
  cfcontents.seek(0, 2)
6099
6207
  cfsize = cfcontents.tell()
6100
6208
  if(ucfsize > cfsize):
6101
6209
  fcsize = format(int(cfsize), 'x').lower()
6102
- fcompression = compression
6210
+ fcompression = curcompression
6103
6211
  fcontents.close()
6104
6212
  fcontents = cfcontents
6105
6213
  if(fcompression == "none"):
@@ -6119,7 +6227,7 @@ if(rarfile_support):
6119
6227
  return False
6120
6228
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
6121
6229
  fp = CompressOpenFileAlt(
6122
- fp, compression, compressionlevel, formatspecs)
6230
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
6123
6231
  try:
6124
6232
  fp.flush()
6125
6233
  if(hasattr(os, "sync")):
@@ -6143,7 +6251,7 @@ if(rarfile_support):
6143
6251
  return outvar
6144
6252
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
6145
6253
  fp = CompressOpenFileAlt(
6146
- fp, compression, compressionlevel, formatspecs)
6254
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
6147
6255
  fp.seek(0, 0)
6148
6256
  upload_file_to_internet_file(fp, outfile)
6149
6257
  if(returnfp):
@@ -6182,7 +6290,7 @@ if(py7zr_support):
6182
6290
  outfile = RemoveWindowsPath(outfile)
6183
6291
  if(not compression or compression == formatspecs['format_magic']):
6184
6292
  compression = "auto"
6185
- if(compression not in compressionlist and compression is None):
6293
+ if(compression not in compressionuselist and compression is None):
6186
6294
  compression = "auto"
6187
6295
  if(verbose):
6188
6296
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
@@ -6194,11 +6302,11 @@ if(py7zr_support):
6194
6302
  pass
6195
6303
  if(outfile == "-" or outfile is None):
6196
6304
  verbose = False
6197
- fp = BytesIO()
6305
+ fp = MkTempFile()
6198
6306
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
6199
6307
  fp = outfile
6200
6308
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
6201
- fp = BytesIO()
6309
+ fp = MkTempFile()
6202
6310
  else:
6203
6311
  fbasename = os.path.splitext(outfile)[0]
6204
6312
  fextname = os.path.splitext(outfile)[1]
@@ -6307,15 +6415,16 @@ if(py7zr_support):
6307
6415
  fgname = ""
6308
6416
  except ImportError:
6309
6417
  fgname = ""
6310
- fcontents = BytesIO()
6418
+ fcontents = MkTempFile()
6311
6419
  fcencoding = "UTF-8"
6312
- curcompression = "none"
6420
+ curcompression = "none"
6313
6421
  if ftype == 0:
6314
6422
  fcontents.write(file_content[member.filename].read())
6423
+ fsize = format(fcontents.tell(), 'x').lower()
6424
+ fcontents.seek(0, 0)
6315
6425
  typechecktest = CheckCompressionType(fcontents, closefp=False)
6316
6426
  fcontents.seek(0, 0)
6317
6427
  fcencoding = GetFileEncoding(fcontents, False)
6318
- fsize = format(fcontents.tell(), 'x').lower()
6319
6428
  file_content[member.filename].close()
6320
6429
  if(typechecktest is False and not compresswholefile):
6321
6430
  fcontents.seek(0, 2)
@@ -6326,13 +6435,13 @@ if(py7zr_support):
6326
6435
  ilmin = 0
6327
6436
  ilcsize = []
6328
6437
  while(ilmin < ilsize):
6329
- cfcontents = BytesIO()
6438
+ cfcontents = MkTempFile()
6330
6439
  fcontents.seek(0, 0)
6331
6440
  shutil.copyfileobj(fcontents, cfcontents)
6332
6441
  fcontents.seek(0, 0)
6333
6442
  cfcontents.seek(0, 0)
6334
6443
  cfcontents = CompressOpenFileAlt(
6335
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
6444
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
6336
6445
  if(cfcontents):
6337
6446
  cfcontents.seek(0, 2)
6338
6447
  ilcsize.append(cfcontents.tell())
@@ -6343,11 +6452,11 @@ if(py7zr_support):
6343
6452
  ilcmin = ilcsize.index(min(ilcsize))
6344
6453
  curcompression = compressionuselist[ilcmin]
6345
6454
  fcontents.seek(0, 0)
6346
- cfcontents = BytesIO()
6455
+ cfcontents = MkTempFile()
6347
6456
  shutil.copyfileobj(fcontents, cfcontents)
6348
6457
  cfcontents.seek(0, 0)
6349
6458
  cfcontents = CompressOpenFileAlt(
6350
- cfcontents, curcompression, compressionlevel, formatspecs)
6459
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
6351
6460
  cfcontents.seek(0, 2)
6352
6461
  cfsize = cfcontents.tell()
6353
6462
  if(ucfsize > cfsize):
@@ -6372,7 +6481,7 @@ if(py7zr_support):
6372
6481
  return False
6373
6482
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
6374
6483
  fp = CompressOpenFileAlt(
6375
- fp, compression, compressionlevel, formatspecs)
6484
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
6376
6485
  try:
6377
6486
  fp.flush()
6378
6487
  if(hasattr(os, "sync")):
@@ -6396,7 +6505,7 @@ if(py7zr_support):
6396
6505
  return outvar
6397
6506
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
6398
6507
  fp = CompressOpenFileAlt(
6399
- fp, compression, compressionlevel, formatspecs)
6508
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
6400
6509
  fp.seek(0, 0)
6401
6510
  upload_file_to_internet_file(fp, outfile)
6402
6511
  if(returnfp):
@@ -6458,7 +6567,7 @@ def FoxFileSeekToFileNum(infile, fmttype="auto", seekto=0, listonly=False, conte
6458
6567
  return False
6459
6568
  fp.seek(0, 0)
6460
6569
  elif(infile == "-"):
6461
- fp = BytesIO()
6570
+ fp = MkTempFile()
6462
6571
  if(hasattr(sys.stdin, "buffer")):
6463
6572
  shutil.copyfileobj(sys.stdin.buffer, fp)
6464
6573
  else:
@@ -6472,7 +6581,7 @@ def FoxFileSeekToFileNum(infile, fmttype="auto", seekto=0, listonly=False, conte
6472
6581
  return False
6473
6582
  fp.seek(0, 0)
6474
6583
  elif(isinstance(infile, bytes) and sys.version_info[0] >= 3):
6475
- fp = BytesIO()
6584
+ fp = MkTempFile()
6476
6585
  fp.write(infile)
6477
6586
  fp.seek(0, 0)
6478
6587
  fp = UncompressFileAlt(fp, formatspecs)
@@ -6773,7 +6882,7 @@ def FoxFileSeekToFileName(infile, fmttype="auto", seekfile=None, listonly=False,
6773
6882
  return False
6774
6883
  fp.seek(0, 0)
6775
6884
  elif(infile == "-"):
6776
- fp = BytesIO()
6885
+ fp = MkTempFile()
6777
6886
  if(hasattr(sys.stdin, "buffer")):
6778
6887
  shutil.copyfileobj(sys.stdin.buffer, fp)
6779
6888
  else:
@@ -6787,7 +6896,7 @@ def FoxFileSeekToFileName(infile, fmttype="auto", seekfile=None, listonly=False,
6787
6896
  return False
6788
6897
  fp.seek(0, 0)
6789
6898
  elif(isinstance(infile, bytes) and sys.version_info[0] >= 3):
6790
- fp = BytesIO()
6899
+ fp = MkTempFile()
6791
6900
  fp.write(infile)
6792
6901
  fp.seek(0, 0)
6793
6902
  fp = UncompressFileAlt(fp, formatspecs)
@@ -7094,7 +7203,7 @@ def FoxFileValidate(infile, fmttype="auto", formatspecs=__file_format_multi_dict
7094
7203
  return False
7095
7204
  fp.seek(0, 0)
7096
7205
  elif(infile == "-"):
7097
- fp = BytesIO()
7206
+ fp = MkTempFile()
7098
7207
  if(hasattr(sys.stdin, "buffer")):
7099
7208
  shutil.copyfileobj(sys.stdin.buffer, fp)
7100
7209
  else:
@@ -7108,7 +7217,7 @@ def FoxFileValidate(infile, fmttype="auto", formatspecs=__file_format_multi_dict
7108
7217
  return False
7109
7218
  fp.seek(0, 0)
7110
7219
  elif(isinstance(infile, bytes) and sys.version_info[0] >= 3):
7111
- fp = BytesIO()
7220
+ fp = MkTempFile()
7112
7221
  fp.write(infile)
7113
7222
  fp.seek(0, 0)
7114
7223
  fp = UncompressFileAlt(fp, formatspecs)
@@ -7446,7 +7555,7 @@ def FoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
7446
7555
  return False
7447
7556
  fp.seek(0, 0)
7448
7557
  elif(infile == "-"):
7449
- fp = BytesIO()
7558
+ fp = MkTempFile()
7450
7559
  if(hasattr(sys.stdin, "buffer")):
7451
7560
  shutil.copyfileobj(sys.stdin.buffer, fp)
7452
7561
  else:
@@ -7460,7 +7569,7 @@ def FoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
7460
7569
  return False
7461
7570
  fp.seek(0, 0)
7462
7571
  elif(isinstance(infile, bytes) and sys.version_info[0] >= 3):
7463
- fp = BytesIO()
7572
+ fp = MkTempFile()
7464
7573
  fp.write(infile)
7465
7574
  fp.seek(0, 0)
7466
7575
  fp = UncompressFileAlt(fp, formatspecs)
@@ -7593,11 +7702,11 @@ def FoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
7593
7702
  if(fcompresstype==formatspecs['format_magic']):
7594
7703
  fcompresstype = ""
7595
7704
  outlist = {'fnumfiles': fnumfiles, 'fformat': formversions[0], 'fcompression': fcompresstype, 'fencoding': fhencoding, 'fversion': formversions[1], 'fostype': fostype, 'fheadersize': fheadsize, 'fsize': CatSizeEnd, 'fnumfields': fnumfields + 2, 'fformatspecs': formatspecs, 'fchecksumtype': fprechecksumtype, 'fheaderchecksum': fprechecksum, 'frawheader': [formstring] + inheader, 'fextrafields': fnumextrafields, 'fextrafieldsize': fnumextrafieldsize, 'fextradata': fextrafieldslist, 'ffilelist': []}
7596
- if(seekstart < 0 and seekstart > fnumfiles):
7705
+ if (seekstart < 0) or (seekstart > fnumfiles):
7597
7706
  seekstart = 0
7598
- if(seekend == 0 or seekend > fnumfiles and seekend < seekstart):
7707
+ if (seekend == 0) or (seekend > fnumfiles) or (seekend < seekstart):
7599
7708
  seekend = fnumfiles
7600
- elif(seekend < 0 and abs(seekend) <= fnumfiles and abs(seekend) >= seekstart):
7709
+ elif (seekend < 0) and (abs(seekend) <= fnumfiles) and (abs(seekend) >= seekstart):
7601
7710
  seekend = fnumfiles - abs(seekend)
7602
7711
  if(seekstart > 0):
7603
7712
  il = 0
@@ -7760,7 +7869,7 @@ def FoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
7760
7869
  outfjsoncontent = {}
7761
7870
  elif(outfjsontype=="list"):
7762
7871
  outfprejsoncontent = fp.read(outfjsonsize).decode("UTF-8")
7763
- flisttmp = BytesIO()
7872
+ flisttmp = MkTempFile()
7764
7873
  flisttmp.write(outfprejsoncontent.encode())
7765
7874
  flisttmp.seek(0)
7766
7875
  outfjsoncontent = ReadFileHeaderData(flisttmp, outfjsonlen, formatspecs['format_delimiter'])
@@ -7813,7 +7922,7 @@ def FoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
7813
7922
  VerbosePrintOut("'" + outfjsonchecksum + "' != " + "'" + injsonfcs + "'")
7814
7923
  return False
7815
7924
  outfcontentstart = fp.tell()
7816
- outfcontents = BytesIO()
7925
+ outfcontents = MkTempFile()
7817
7926
  pyhascontents = False
7818
7927
  if(outfsize > 0 and not listonly):
7819
7928
  if(outfcompression == "none" or outfcompression == "" or outfcompression == "auto"):
@@ -7838,7 +7947,7 @@ def FoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
7838
7947
  cfcontents = UncompressFileAlt(
7839
7948
  outfcontents, formatspecs)
7840
7949
  cfcontents.seek(0, 0)
7841
- outfcontents = BytesIO()
7950
+ outfcontents = MkTempFile()
7842
7951
  shutil.copyfileobj(cfcontents, outfcontents)
7843
7952
  cfcontents.close()
7844
7953
  outfcontents.seek(0, 0)
@@ -7888,7 +7997,7 @@ def MultipleFoxFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listo
7888
7997
  infile = [infile]
7889
7998
  outretval = {}
7890
7999
  for curfname in infile:
7891
- curretfile = outretval.update({curfname: FoxFileToArray(curfname, fmttype, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend, returnfp)})
8000
+ curretfile[curfname] = FoxFileToArray(curfname, fmttype, seekstart, seekend, listonly, contentasfile, uncompress, skipchecksum, formatspecs, seektoend, returnfp)
7892
8001
  return outretval
7893
8002
 
7894
8003
  def MultipleFoxFilesToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=False, contentasfile=True, uncompress=True, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, returnfp=False):
@@ -7899,7 +8008,7 @@ def FoxFileStringToArray(instr, seekstart=0, seekend=0, listonly=False, contenta
7899
8008
  checkcompressfile = CheckCompressionSubType(infile, formatspecs, True)
7900
8009
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
7901
8010
  formatspecs = formatspecs[checkcompressfile]
7902
- fp = BytesIO(instr)
8011
+ fp = MkTempFile(instr)
7903
8012
  listfoxfiles = FoxFileToArray(fp, "auto", seekstart, seekend, listonly, contentasfile, True, skipchecksum, formatspecs, seektoend, returnfp)
7904
8013
  return listfoxfiles
7905
8014
 
@@ -7908,7 +8017,7 @@ def TarFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentasfile
7908
8017
  checkcompressfile = CheckCompressionSubType(infile, formatspecs, True)
7909
8018
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
7910
8019
  formatspecs = formatspecs[checkcompressfile]
7911
- fp = BytesIO()
8020
+ fp = MkTempFile()
7912
8021
  fp = PackFoxFileFromTarFile(
7913
8022
  infile, fp, "auto", True, None, compressionlistalt, "crc32", [], formatspecs, False, True)
7914
8023
  listfoxfiles = FoxFileToArray(fp, "auto", seekstart, seekend, listonly, contentasfile, True, skipchecksum, formatspecs, seektoend, returnfp)
@@ -7919,7 +8028,7 @@ def ZipFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentasfile
7919
8028
  checkcompressfile = CheckCompressionSubType(infile, formatspecs, True)
7920
8029
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
7921
8030
  formatspecs = formatspecs[checkcompressfile]
7922
- fp = BytesIO()
8031
+ fp = MkTempFile()
7923
8032
  fp = PackFoxFileFromZipFile(
7924
8033
  infile, fp, "auto", True, None, compressionlistalt, "crc32", [], formatspecs, False, True)
7925
8034
  listfoxfiles = FoxFileToArray(fp, "auto", seekstart, seekend, listonly, contentasfile, True, skipchecksum, formatspecs, seektoend, returnfp)
@@ -7935,7 +8044,7 @@ if(rarfile_support):
7935
8044
  checkcompressfile = CheckCompressionSubType(infile, formatspecs, True)
7936
8045
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
7937
8046
  formatspecs = formatspecs[checkcompressfile]
7938
- fp = BytesIO()
8047
+ fp = MkTempFile()
7939
8048
  fp = PackFoxFileFromRarFile(
7940
8049
  infile, fp, "auto", True, None, compressionlistalt, "crc32", [], formatspecs, False, True)
7941
8050
  listfoxfiles = FoxFileToArray(fp, "auto", seekstart, seekend, listonly, contentasfile, True, skipchecksum, formatspecs, seektoend, returnfp)
@@ -7950,7 +8059,7 @@ if(py7zr_support):
7950
8059
  checkcompressfile = CheckCompressionSubType(infile, formatspecs, True)
7951
8060
  if(IsNestedDict(formatspecs) and checkcompressfile in formatspecs):
7952
8061
  formatspecs = formatspecs[checkcompressfile]
7953
- fp = BytesIO()
8062
+ fp = MkTempFile()
7954
8063
  fp = PackFoxFileFromSevenZipFile(
7955
8064
  infile, fp, "auto", True, None, compressionlistalt, "crc32", [], formatspecs, False, True)
7956
8065
  listfoxfiles = FoxFileToArray(fp, "auto", seekstart, seekend, listonly, contentasfile, True, skipchecksum, formatspecs, seektoend, returnfp)
@@ -7977,7 +8086,7 @@ def InFileToArray(infile, seekstart=0, seekend=0, listonly=False, contentasfile=
7977
8086
 
7978
8087
 
7979
8088
  def ListDirToArray(infiles, dirlistfromtxt=False, fmttype=__file_format_default__, compression="auto", compresswholefile=True, compressionlevel=None, followlink=False, seekstart=0, seekend=0, listonly=False, skipchecksum=False, checksumtype=["crc32", "crc32", "crc32"], extradata=[], formatspecs=__file_format_dict__, verbose=False, seektoend=False, returnfp=False):
7980
- outarray = BytesIO()
8089
+ outarray = MkTempFile()
7981
8090
  packform = PackFoxFile(infiles, outarray, dirlistfromtxt, fmttype, compression, compresswholefile,
7982
8091
  compressionlevel, followlink, checksumtype, extradata, formatspecs, verbose, True)
7983
8092
  listfoxfiles = FoxFileToArray(outarray, "auto", seekstart, seekend, listonly, True, skipchecksum, formatspecs, seektoend, returnfp)
@@ -8072,7 +8181,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8072
8181
  outfile = RemoveWindowsPath(outfile)
8073
8182
  if(not compression or compression == formatspecs['format_magic']):
8074
8183
  compression = "auto"
8075
- if(compression not in compressionlist and compression is None):
8184
+ if(compression not in compressionuselist and compression is None):
8076
8185
  compression = "auto"
8077
8186
  if(verbose):
8078
8187
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
@@ -8086,11 +8195,11 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8086
8195
  return False
8087
8196
  if(outfile == "-" or outfile is None):
8088
8197
  verbose = False
8089
- fp = BytesIO()
8198
+ fp = MkTempFile()
8090
8199
  elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
8091
8200
  fp = outfile
8092
8201
  elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
8093
- fp = BytesIO()
8202
+ fp = MkTempFile()
8094
8203
  else:
8095
8204
  fbasename = os.path.splitext(outfile)[0]
8096
8205
  fextname = os.path.splitext(outfile)[1]
@@ -8178,7 +8287,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8178
8287
  jsondata = listfoxfiles['ffilelist'][reallcfi]['fjsondata']
8179
8288
  fcontents = listfoxfiles['ffilelist'][reallcfi]['fcontents']
8180
8289
  if(not listfoxfiles['ffilelist'][reallcfi]['fcontentasfile']):
8181
- fcontents = BytesIO(fcontents)
8290
+ fcontents = MkTempFile(fcontents)
8182
8291
  typechecktest = CheckCompressionType(fcontents, closefp=False)
8183
8292
  fcontents.seek(0, 0)
8184
8293
  fcencoding = GetFileEncoding(fcontents, False)
@@ -8194,13 +8303,13 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8194
8303
  ilmin = 0
8195
8304
  ilcsize = []
8196
8305
  while(ilmin < ilsize):
8197
- cfcontents = BytesIO()
8306
+ cfcontents = MkTempFile()
8198
8307
  fcontents.seek(0, 0)
8199
8308
  shutil.copyfileobj(fcontents, cfcontents)
8200
8309
  fcontents.seek(0, 0)
8201
8310
  cfcontents.seek(0, 0)
8202
8311
  cfcontents = CompressOpenFileAlt(
8203
- cfcontents, compressionuselist[ilmin], compressionlevel, formatspecs)
8312
+ cfcontents, compressionuselist[ilmin], compressionlevel, compressionuselist, formatspecs)
8204
8313
  if(cfcontents):
8205
8314
  cfcontents.seek(0, 2)
8206
8315
  ilcsize.append(cfcontents.tell())
@@ -8211,11 +8320,11 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8211
8320
  ilcmin = ilcsize.index(min(ilcsize))
8212
8321
  curcompression = compressionuselist[ilcmin]
8213
8322
  fcontents.seek(0, 0)
8214
- cfcontents = BytesIO()
8323
+ cfcontents = MkTempFile()
8215
8324
  shutil.copyfileobj(fcontents, cfcontents)
8216
8325
  cfcontents.seek(0, 0)
8217
8326
  cfcontents = CompressOpenFileAlt(
8218
- cfcontents, curcompression, compressionlevel, formatspecs)
8327
+ cfcontents, curcompression, compressionlevel, compressionuselist, formatspecs)
8219
8328
  cfcontents.seek(0, 2)
8220
8329
  cfsize = cfcontents.tell()
8221
8330
  if(ucfsize > cfsize):
@@ -8224,10 +8333,10 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8224
8333
  fcontents.close()
8225
8334
  fcontents = cfcontents
8226
8335
  if followlink:
8227
- if(listarchivefiles['ffilelist'][reallcfi]['ftype'] == 1 or listarchivefiles['ffilelist'][reallcfi]['ftype'] == 2):
8228
- getflinkpath = listarchivefiles['ffilelist'][reallcfi]['flinkname']
8229
- flinkid = prelistarchivefiles['filetoid'][getflinkpath]
8230
- flinkinfo = listarchivefiles['ffilelist'][flinkid]
8336
+ if(listfoxfiles['ffilelist'][reallcfi]['ftype'] == 1 or listfoxfiles['ffilelist'][reallcfi]['ftype'] == 2):
8337
+ getflinkpath = listfoxfiles['ffilelist'][reallcfi]['flinkname']
8338
+ flinkid = prelistfoxfiles['filetoid'][getflinkpath]
8339
+ flinkinfo = listfoxfiles['ffilelist'][flinkid]
8231
8340
  fheadersize = format(
8232
8341
  int(flinkinfo['fheadersize']), 'x').lower()
8233
8342
  fsize = format(int(flinkinfo['fsize']), 'x').lower()
@@ -8260,11 +8369,11 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8260
8369
  extradata = flinkinfo['fjsondata']
8261
8370
  fcontents = flinkinfo['fcontents']
8262
8371
  if(not flinkinfo['fcontentasfile']):
8263
- fcontents = BytesIO(fcontents)
8372
+ fcontents = MkTempFile(fcontents)
8264
8373
  ftypehex = format(flinkinfo['ftype'], 'x').lower()
8265
8374
  else:
8266
8375
  ftypehex = format(
8267
- listarchivefiles['ffilelist'][reallcfi]['ftype'], 'x').lower()
8376
+ listfoxfiles['ffilelist'][reallcfi]['ftype'], 'x').lower()
8268
8377
  fcurfid = format(curfid, 'x').lower()
8269
8378
  if(not followlink and finode != 0):
8270
8379
  if(listfoxfiles['ffilelist'][reallcfi]['ftype'] != 1):
@@ -8295,7 +8404,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8295
8404
  return False
8296
8405
  if(outfile == "-" or outfile is None or hasattr(outfile, "read") or hasattr(outfile, "write")):
8297
8406
  fp = CompressOpenFileAlt(
8298
- fp, compression, compressionlevel, formatspecs)
8407
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
8299
8408
  try:
8300
8409
  fp.flush()
8301
8410
  if(hasattr(os, "sync")):
@@ -8319,7 +8428,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8319
8428
  return outvar
8320
8429
  elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
8321
8430
  fp = CompressOpenFileAlt(
8322
- fp, compression, compressionlevel, formatspecs)
8431
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
8323
8432
  fp.seek(0, 0)
8324
8433
  upload_file_to_internet_file(fp, outfile)
8325
8434
  if(returnfp):
@@ -8331,14 +8440,14 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
8331
8440
 
8332
8441
 
8333
8442
  def RePackFoxFileFromString(instr, outfile, fmttype="auto", compression="auto", compresswholefile=True, compressionlevel=None, compressionuselist=compressionlistalt, checksumtype=["crc32", "crc32", "crc32"], skipchecksum=False, extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False):
8334
- fp = BytesIO(instr)
8443
+ fp = MkTempFile(instr)
8335
8444
  listfoxfiles = RePackFoxFile(fp, outfile, fmttype, compression, compresswholefile, compressionlevel, compressionuselist,
8336
8445
  checksumtype, skipchecksum, extradata, formatspecs, verbose, returnfp)
8337
8446
  return listfoxfiles
8338
8447
 
8339
8448
 
8340
8449
  def PackFoxFileFromListDir(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compression="auto", compresswholefile=True, compressionlevel=None, compressionuselist=compressionlistalt, followlink=False, skipchecksum=False, checksumtype=["crc32", "crc32", "crc32"], extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False):
8341
- outarray = BytesIO()
8450
+ outarray = MkTempFile()
8342
8451
  packform = PackFoxFile(infiles, outarray, dirlistfromtxt, fmttype, compression, compresswholefile,
8343
8452
  compressionlevel, compressionuselist, followlink, checksumtype, extradata, formatspecs, verbose, True)
8344
8453
  listfoxfiles = RePackFoxFile(outarray, outfile, fmttype, compression, compresswholefile,
@@ -8396,7 +8505,7 @@ def UnPackFoxFile(infile, outdir=None, followlink=False, seekstart=0, seekend=0,
8396
8505
  if(listfoxfiles['ffilelist'][lcfi]['ftype'] == 0 or listfoxfiles['ffilelist'][lcfi]['ftype'] == 7):
8397
8506
  with open(PrependPath(outdir, listfoxfiles['ffilelist'][lcfi]['fname']), "wb") as fpc:
8398
8507
  if(not listfoxfiles['ffilelist'][lcfi]['fcontentasfile']):
8399
- listfoxfiles['ffilelist'][lcfi]['fcontents'] = BytesIO(
8508
+ listfoxfiles['ffilelist'][lcfi]['fcontents'] = MkTempFile(
8400
8509
  listfoxfiles['ffilelist'][lcfi]['fcontents'])
8401
8510
  listfoxfiles['ffilelist'][lcfi]['fcontents'].seek(0, 0)
8402
8511
  shutil.copyfileobj(
@@ -8448,7 +8557,7 @@ def UnPackFoxFile(infile, outdir=None, followlink=False, seekstart=0, seekend=0,
8448
8557
  if(flinkinfo['ftype'] == 0 or flinkinfo['ftype'] == 7):
8449
8558
  with open(PrependPath(outdir, listfoxfiles['ffilelist'][lcfi]['fname']), "wb") as fpc:
8450
8559
  if(not flinkinfo['fcontentasfile']):
8451
- flinkinfo['fcontents'] = BytesIO(
8560
+ flinkinfo['fcontents'] = MkTempFile(
8452
8561
  flinkinfo['fcontents'])
8453
8562
  flinkinfo['fcontents'].seek(0, 0)
8454
8563
  shutil.copyfileobj(flinkinfo['fcontents'], fpc)
@@ -8527,7 +8636,7 @@ def UnPackFoxFile(infile, outdir=None, followlink=False, seekstart=0, seekend=0,
8527
8636
  if(flinkinfo['ftype'] == 0 or flinkinfo['ftype'] == 7):
8528
8637
  with open(PrependPath(outdir, listfoxfiles['ffilelist'][lcfi]['fname']), "wb") as fpc:
8529
8638
  if(not flinkinfo['fcontentasfile']):
8530
- flinkinfo['fcontents'] = BytesIO(
8639
+ flinkinfo['fcontents'] = MkTempFile(
8531
8640
  flinkinfo['fcontents'])
8532
8641
  flinkinfo['fcontents'].seek(0, 0)
8533
8642
  shutil.copyfileobj(flinkinfo['fcontents'], fpc)
@@ -8605,7 +8714,7 @@ def UnPackFoxFile(infile, outdir=None, followlink=False, seekstart=0, seekend=0,
8605
8714
 
8606
8715
 
8607
8716
  def UnPackFoxFileString(instr, outdir=None, followlink=False, seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, verbose=False, returnfp=False):
8608
- fp = BytesIO(instr)
8717
+ fp = MkTempFile(instr)
8609
8718
  listfoxfiles = UnPackFoxFile(fp, outdir, followlink, seekstart, seekend, skipchecksum, formatspecs, seektoend, verbose, returnfp)
8610
8719
  return listfoxfiles
8611
8720
 
@@ -8628,57 +8737,57 @@ def FoxFileListFiles(infile, fmttype="auto", seekstart=0, seekend=0, skipchecksu
8628
8737
  if(verbose):
8629
8738
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
8630
8739
  if(isinstance(infile, dict)):
8631
- listarchivefiles = infile
8740
+ listfoxfiles = infile
8632
8741
  else:
8633
8742
  if(infile != "-" and not hasattr(infile, "read") and not hasattr(infile, "write") and not (sys.version_info[0] >= 3 and isinstance(infile, bytes))):
8634
8743
  infile = RemoveWindowsPath(infile)
8635
- listarchivefiles = FoxFileToArray(infile, fmttype, seekstart, seekend, True, False, False, skipchecksum, formatspecs, seektoend, returnfp)
8636
- if(not listarchivefiles):
8744
+ listfoxfiles = FoxFileToArray(infile, fmttype, seekstart, seekend, True, False, False, skipchecksum, formatspecs, seektoend, returnfp)
8745
+ if(not listfoxfiles):
8637
8746
  return False
8638
- lenlist = len(listarchivefiles['ffilelist'])
8639
- fnumfiles = int(listarchivefiles['fnumfiles'])
8747
+ lenlist = len(listfoxfiles['ffilelist'])
8748
+ fnumfiles = int(listfoxfiles['fnumfiles'])
8640
8749
  lcfi = 0
8641
- lcfx = int(listarchivefiles['fnumfiles'])
8642
- if(lenlist > listarchivefiles['fnumfiles'] or lenlist < listarchivefiles['fnumfiles']):
8750
+ lcfx = int(listfoxfiles['fnumfiles'])
8751
+ if(lenlist > listfoxfiles['fnumfiles'] or lenlist < listfoxfiles['fnumfiles']):
8643
8752
  lcfx = int(lenlist)
8644
8753
  else:
8645
- lcfx = int(listarchivefiles['fnumfiles'])
8754
+ lcfx = int(listfoxfiles['fnumfiles'])
8646
8755
  returnval = {}
8647
8756
  while(lcfi < lcfx):
8648
- returnval.update({lcfi: listarchivefiles['ffilelist'][lcfi]['fname']})
8757
+ returnval.update({lcfi: listfoxfiles['ffilelist'][lcfi]['fname']})
8649
8758
  if(not verbose):
8650
- VerbosePrintOut(listarchivefiles['ffilelist'][lcfi]['fname'])
8759
+ VerbosePrintOut(listfoxfiles['ffilelist'][lcfi]['fname'])
8651
8760
  if(verbose):
8652
8761
  permissions = {'access': {'0': ('---'), '1': ('--x'), '2': ('-w-'), '3': ('-wx'), '4': (
8653
8762
  'r--'), '5': ('r-x'), '6': ('rw-'), '7': ('rwx')}, 'roles': {0: 'owner', 1: 'group', 2: 'other'}}
8654
- printfname = listarchivefiles['ffilelist'][lcfi]['fname']
8655
- if(listarchivefiles['ffilelist'][lcfi]['ftype'] == 1):
8656
- printfname = listarchivefiles['ffilelist'][lcfi]['fname'] + \
8657
- " link to " + listarchivefiles['ffilelist'][lcfi]['flinkname']
8658
- if(listarchivefiles['ffilelist'][lcfi]['ftype'] == 2):
8659
- printfname = listarchivefiles['ffilelist'][lcfi]['fname'] + \
8660
- " -> " + listarchivefiles['ffilelist'][lcfi]['flinkname']
8661
- fuprint = listarchivefiles['ffilelist'][lcfi]['funame']
8763
+ printfname = listfoxfiles['ffilelist'][lcfi]['fname']
8764
+ if(listfoxfiles['ffilelist'][lcfi]['ftype'] == 1):
8765
+ printfname = listfoxfiles['ffilelist'][lcfi]['fname'] + \
8766
+ " link to " + listfoxfiles['ffilelist'][lcfi]['flinkname']
8767
+ if(listfoxfiles['ffilelist'][lcfi]['ftype'] == 2):
8768
+ printfname = listfoxfiles['ffilelist'][lcfi]['fname'] + \
8769
+ " -> " + listfoxfiles['ffilelist'][lcfi]['flinkname']
8770
+ fuprint = listfoxfiles['ffilelist'][lcfi]['funame']
8662
8771
  if(len(fuprint) <= 0):
8663
- fuprint = listarchivefiles['ffilelist'][lcfi]['fuid']
8664
- fgprint = listarchivefiles['ffilelist'][lcfi]['fgname']
8772
+ fuprint = listfoxfiles['ffilelist'][lcfi]['fuid']
8773
+ fgprint = listfoxfiles['ffilelist'][lcfi]['fgname']
8665
8774
  if(len(fgprint) <= 0):
8666
- fgprint = listarchivefiles['ffilelist'][lcfi]['fgid']
8775
+ fgprint = listfoxfiles['ffilelist'][lcfi]['fgid']
8667
8776
  if(newstyle):
8668
- VerbosePrintOut(ftype_to_str(listarchivefiles['ffilelist'][lcfi]['ftype']) + "\t" + listarchivefiles['ffilelist'][lcfi]['fcompression'] + "\t" + str(
8669
- listarchivefiles['ffilelist'][lcfi]['fsize']).rjust(15) + "\t" + printfname)
8777
+ VerbosePrintOut(ftype_to_str(listfoxfiles['ffilelist'][lcfi]['ftype']) + "\t" + listfoxfiles['ffilelist'][lcfi]['fcompression'] + "\t" + str(
8778
+ listfoxfiles['ffilelist'][lcfi]['fsize']).rjust(15) + "\t" + printfname)
8670
8779
  else:
8671
- VerbosePrintOut(PrintPermissionString(listarchivefiles['ffilelist'][lcfi]['fmode'], listarchivefiles['ffilelist'][lcfi]['ftype']) + " " + str(fuprint) + "/" + str(fgprint) + " " + str(
8672
- listarchivefiles['ffilelist'][lcfi]['fsize']).rjust(15) + " " + datetime.datetime.utcfromtimestamp(listarchivefiles['ffilelist'][lcfi]['fmtime']).strftime('%Y-%m-%d %H:%M') + " " + printfname)
8780
+ VerbosePrintOut(PrintPermissionString(listfoxfiles['ffilelist'][lcfi]['fmode'], listfoxfiles['ffilelist'][lcfi]['ftype']) + " " + str(fuprint) + "/" + str(fgprint) + " " + str(
8781
+ listfoxfiles['ffilelist'][lcfi]['fsize']).rjust(15) + " " + datetime.datetime.utcfromtimestamp(listfoxfiles['ffilelist'][lcfi]['fmtime']).strftime('%Y-%m-%d %H:%M') + " " + printfname)
8673
8782
  lcfi = lcfi + 1
8674
8783
  if(returnfp):
8675
- return listarchivefiles['fp']
8784
+ return listfoxfiles['fp']
8676
8785
  else:
8677
8786
  return True
8678
8787
 
8679
8788
 
8680
8789
  def FoxFileStringListFiles(instr, seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, verbose=False, newstyle=False, returnfp=False):
8681
- fp = BytesIO(instr)
8790
+ fp = MkTempFile(instr)
8682
8791
  listfoxfiles = FoxFileListFiles(
8683
8792
  instr, seekstart, seekend, skipchecksum, formatspecs, seektoend, verbose, newstyle, returnfp)
8684
8793
  return listfoxfiles
@@ -8688,7 +8797,7 @@ def TarFileListFiles(infile, verbose=False, returnfp=False):
8688
8797
  if(verbose):
8689
8798
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
8690
8799
  if(infile == "-"):
8691
- infile = BytesIO()
8800
+ infile = MkTempFile()
8692
8801
  if(hasattr(sys.stdin, "buffer")):
8693
8802
  shutil.copyfileobj(sys.stdin.buffer, infile)
8694
8803
  else:
@@ -8728,7 +8837,7 @@ def TarFileListFiles(infile, verbose=False, returnfp=False):
8728
8837
  if 'zstandard' in sys.modules:
8729
8838
  infile = ZstdFile(fileobj=infile, mode="rb")
8730
8839
  elif 'pyzstd' in sys.modules:
8731
- fp = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
8840
+ infile = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
8732
8841
  tarfp = tarfile.open(fileobj=infile, mode="r")
8733
8842
  else:
8734
8843
  tarfp = tarfile.open(fileobj=infile, mode="r")
@@ -8740,7 +8849,7 @@ def TarFileListFiles(infile, verbose=False, returnfp=False):
8740
8849
  if 'zstandard' in sys.modules:
8741
8850
  infile = ZstdFile(fileobj=infile, mode="rb")
8742
8851
  elif 'pyzstd' in sys.modules:
8743
- fp = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
8852
+ infile = pyzstd.zstdfile.ZstdFile(fileobj=infile, mode="rb")
8744
8853
  tarfp = tarfile.open(fileobj=infile, mode="r")
8745
8854
  else:
8746
8855
  tarfp = tarfile.open(infile, "r")
@@ -8813,7 +8922,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
8813
8922
  if(verbose):
8814
8923
  logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
8815
8924
  if(infile == "-"):
8816
- infile = BytesIO()
8925
+ infile = MkTempFile()
8817
8926
  if(hasattr(sys.stdin, "buffer")):
8818
8927
  shutil.copyfileobj(sys.stdin.buffer, infile)
8819
8928
  else:
@@ -9209,7 +9318,7 @@ def InFileListFiles(infile, verbose=False, formatspecs=__file_format_multi_dict_
9209
9318
 
9210
9319
 
9211
9320
  def ListDirListFiles(infiles, dirlistfromtxt=False, compression="auto", compresswholefile=True, compressionlevel=None, followlink=False, seekstart=0, seekend=0, skipchecksum=False, checksumtype=["crc32", "crc32", "crc32"], formatspecs=__file_format_dict__, seektoend=False, verbose=False, returnfp=False):
9212
- outarray = BytesIO()
9321
+ outarray = MkTempFile()
9213
9322
  packform = PackFoxFile(infiles, outarray, dirlistfromtxt, compression, compresswholefile,
9214
9323
  compressionlevel, followlink, checksumtype, formatspecs, False, True)
9215
9324
  listfoxfiles = FoxFileListFiles(
@@ -9227,32 +9336,32 @@ def make_empty_archive_file_pointer_neo(fp, fmttype=None, checksumtype='crc32',
9227
9336
  return make_empty_file_pointer_neo(fp, fmttype, checksumtype, formatspecs, encoding)
9228
9337
 
9229
9338
  def make_empty_file_neo(outfile=None, fmttype=None, checksumtype='crc32', formatspecs=__file_format_multi_dict__, encoding='UTF-8', returnfp=False):
9230
- return MakeEmptyFile(outfile, fmttype, "auto", False, None, checksumtype, formatspecs, returnfp)
9339
+ return MakeEmptyFile(outfile, fmttype, "auto", False, None, compressionlistalt, checksumtype, formatspecs, returnfp)
9231
9340
 
9232
9341
  def make_empty_archive_file_neo(outfile=None, fmttype=None, checksumtype='crc32', formatspecs=__file_format_multi_dict__, encoding='UTF-8', returnfp=False):
9233
9342
  return make_empty_file_neo(outfile, fmttype, checksumtype, formatspecs, encoding, returnfp)
9234
9343
 
9235
9344
  def pack_neo(infiles, outfile=None, formatspecs=__file_format_multi_dict__, checksumtypes=["crc32", "crc32", "crc32", "crc32"], encoding="UTF-8", compression="auto", compression_level=None, returnfp=False):
9236
- return PackFoxFile(infiles, outfile, False, "auto", compression, False, compression_level, compressionlistalt, False, checksumtypes, [], {}, formatspecs, False, returnfp)
9345
+ return PackArchiveFile(infiles, outfile, False, "auto", compression, False, compression_level, compressionlistalt, False, checksumtypes, [], {}, formatspecs, False, returnfp)
9237
9346
 
9238
9347
  def archive_to_array_neo(infile, formatspecs=__file_format_multi_dict__, listonly=False, skipchecksum=False, uncompress=True, returnfp=False):
9239
- return FoxFileToArray(infile, "auto", 0, 0, listonly, True, uncompress, skipchecksum, formatspecs, False, returnfp)
9348
+ return ArchiveFileToArray(infile, "auto", 0, 0, listonly, True, uncompress, skipchecksum, formatspecs, False, returnfp)
9240
9349
 
9241
9350
  def unpack_neo(infile, outdir='.', formatspecs=__file_format_multi_dict__, skipchecksum=False, uncompress=True, returnfp=False):
9242
- return UnPackFoxFile(infile, outdir, False, 0, 0, skipchecksum, formatspecs, True, True, False, False, returnfp)
9351
+ return UnPackArchiveFile(infile, outdir, False, 0, 0, skipchecksum, formatspecs, True, True, False, False, returnfp)
9243
9352
 
9244
9353
  def repack_neo(infile, outfile=None, formatspecs=__file_format_dict__, checksumtypes=["crc32", "crc32", "crc32", "crc32"], compression="auto", compression_level=None, returnfp=False):
9245
- return RePackFoxFile(infile, outfile, "auto", compression, False, compression_level, compressionlistalt, False, 0, 0, checksumtypes, False, [], {}, formatspecs, False, False, returnfp)
9354
+ return RePackArchiveFile(infile, outfile, "auto", compression, False, compression_level, compressionlistalt, False, 0, 0, checksumtypes, False, [], {}, formatspecs, False, False, returnfp)
9246
9355
 
9247
9356
  def archivefilevalidate_neo(infile, formatspecs=__file_format_multi_dict__, verbose=False, return_details=False, returnfp=False):
9248
- return FoxFileValidate(infile, "auto", formatspecs, False, verbose, returnfp)
9357
+ return ArchiveFileValidate(infile, "auto", formatspecs, False, verbose, returnfp)
9249
9358
 
9250
9359
  def archivefilelistfiles_neo(infile, formatspecs=__file_format_multi_dict__, advanced=False, include_dirs=True, returnfp=False):
9251
- return FoxFileListFiles(infile, "auto", 0, 0, False, formatspecs, False, True, advanced, returnfp)
9360
+ return ArchiveFileListFiles(infile, "auto", 0, 0, False, formatspecs, False, True, advanced, returnfp)
9252
9361
 
9253
9362
  def convert_foreign_to_neo(infile, outfile=None, formatspecs=__file_format_multi_dict__, checksumtypes=["crc32", "crc32", "crc32", "crc32"], compression="auto", compression_level=None, returnfp=False):
9254
9363
  intmp = InFileToArray(infile, 0, 0, False, True, False, formatspecs, False, False)
9255
- return RePackFoxFile(intmp, outfile, "auto", compression, False, compression_level, compressionlistalt, False, 0, 0, checksumtypes, False, [], {}, formatspecs, False, False, returnfp)
9364
+ return RePackArchiveFile(intmp, outfile, "auto", compression, False, compression_level, compressionlistalt, False, 0, 0, checksumtypes, False, [], {}, formatspecs, False, False, returnfp)
9256
9365
 
9257
9366
  def download_file_from_ftp_file(url):
9258
9367
  urlparts = urlparse(url)
@@ -9295,7 +9404,7 @@ def download_file_from_ftp_file(url):
9295
9404
  ftp.login(urlparts.username, urlparts.password)
9296
9405
  if(urlparts.scheme == "ftps"):
9297
9406
  ftp.prot_p()
9298
- ftpfile = BytesIO()
9407
+ ftpfile = MkTempFile()
9299
9408
  ftp.retrbinary("RETR "+urlparts.path, ftpfile.write)
9300
9409
  #ftp.storbinary("STOR "+urlparts.path, ftpfile.write);
9301
9410
  ftp.close()
@@ -9356,7 +9465,7 @@ def upload_file_to_ftp_file(ftpfile, url):
9356
9465
 
9357
9466
 
9358
9467
  def upload_file_to_ftp_string(ftpstring, url):
9359
- ftpfileo = BytesIO(ftpstring)
9468
+ ftpfileo = MkTempFile(ftpstring)
9360
9469
  ftpfile = upload_file_to_ftp_file(ftpfileo, url)
9361
9470
  ftpfileo.close()
9362
9471
  return ftpfile
@@ -9408,7 +9517,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
9408
9517
  return download_file_from_ftp_file(url)
9409
9518
 
9410
9519
  # Create a temporary file object
9411
- httpfile = BytesIO()
9520
+ httpfile = MkTempFile()
9412
9521
 
9413
9522
  # 1) Requests branch
9414
9523
  if usehttp == 'requests' and haverequests:
@@ -9516,7 +9625,7 @@ if(haveparamiko):
9516
9625
  log.info("Error With URL "+url)
9517
9626
  return False
9518
9627
  sftp = ssh.open_sftp()
9519
- sftpfile = BytesIO()
9628
+ sftpfile = MkTempFile()
9520
9629
  sftp.getfo(urlparts.path, sftpfile)
9521
9630
  sftp.close()
9522
9631
  ssh.close()
@@ -9586,7 +9695,7 @@ else:
9586
9695
 
9587
9696
  if(haveparamiko):
9588
9697
  def upload_file_to_sftp_string(sftpstring, url):
9589
- sftpfileo = BytesIO(sftpstring)
9698
+ sftpfileo = MkTempFile(sftpstring)
9590
9699
  sftpfile = upload_file_to_sftp_files(sftpfileo, url)
9591
9700
  sftpfileo.close()
9592
9701
  return sftpfile
@@ -9632,7 +9741,7 @@ if(havepysftp):
9632
9741
  log.info("Error With URL "+url)
9633
9742
  return False
9634
9743
  sftp = ssh.open_sftp()
9635
- sftpfile = BytesIO()
9744
+ sftpfile = MkTempFile()
9636
9745
  sftp.getfo(urlparts.path, sftpfile)
9637
9746
  sftp.close()
9638
9747
  ssh.close()
@@ -9699,7 +9808,7 @@ else:
9699
9808
 
9700
9809
  if(havepysftp):
9701
9810
  def upload_file_to_pysftp_string(sftpstring, url):
9702
- sftpfileo = BytesIO(sftpstring)
9811
+ sftpfileo = MkTempFile(sftpstring)
9703
9812
  sftpfile = upload_file_to_pysftp_file(ftpfileo, url)
9704
9813
  sftpfileo.close()
9705
9814
  return sftpfile
@@ -9774,9 +9883,9 @@ def upload_file_to_internet_file(ifp, url):
9774
9883
  return False
9775
9884
 
9776
9885
 
9777
- def upload_file_to_internet_compress_file(ifp, url, compression="auto", compressionlevel=None, formatspecs=__file_format_dict__):
9886
+ def upload_file_to_internet_compress_file(ifp, url, compression="auto", compressionlevel=None, compressionuselist=compressionlistalt, formatspecs=__file_format_dict__):
9778
9887
  fp = CompressOpenFileAlt(
9779
- fp, compression, compressionlevel, formatspecs)
9888
+ fp, compression, compressionlevel, compressionuselist, formatspecs)
9780
9889
  if(not foxfileout):
9781
9890
  return False
9782
9891
  fp.seek(0, 0)
@@ -9800,9 +9909,10 @@ def upload_file_to_internet_string(ifp, url):
9800
9909
  return False
9801
9910
 
9802
9911
 
9803
- def upload_file_to_internet_compress_string(ifp, url, compression="auto", compressionlevel=None, formatspecs=__file_format_dict__):
9912
+ def upload_file_to_internet_compress_string(ifp, url, compression="auto", compressionlevel=None, compressionuselist=compressionlistalt, formatspecs=__file_format_dict__):
9913
+ internetfileo = MkTempFile(ifp)
9804
9914
  fp = CompressOpenFileAlt(
9805
- BytesIO(ifp), compression, compressionlevel, formatspecs)
9915
+ internetfileo, compression, compressionlevel, compressionuselist, formatspecs)
9806
9916
  if(not foxfileout):
9807
9917
  return False
9808
9918
  fp.seek(0, 0)