PyCatFile 0.12.8__tar.gz → 0.13.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pycatfile-0.12.8 → pycatfile-0.13.2}/PKG-INFO +1 -1
- {pycatfile-0.12.8 → pycatfile-0.13.2}/PyCatFile.egg-info/PKG-INFO +1 -1
- {pycatfile-0.12.8 → pycatfile-0.13.2}/catfile.py +1 -1
- {pycatfile-0.12.8 → pycatfile-0.13.2}/neocatfile.py +1 -1
- {pycatfile-0.12.8 → pycatfile-0.13.2}/pycatfile.py +576 -85
- {pycatfile-0.12.8 → pycatfile-0.13.2}/setup.py +1 -1
- {pycatfile-0.12.8 → pycatfile-0.13.2}/LICENSE +0 -0
- {pycatfile-0.12.8 → pycatfile-0.13.2}/PyCatFile.egg-info/SOURCES.txt +0 -0
- {pycatfile-0.12.8 → pycatfile-0.13.2}/PyCatFile.egg-info/dependency_links.txt +0 -0
- {pycatfile-0.12.8 → pycatfile-0.13.2}/PyCatFile.egg-info/top_level.txt +0 -0
- {pycatfile-0.12.8 → pycatfile-0.13.2}/PyCatFile.egg-info/zip-safe +0 -0
- {pycatfile-0.12.8 → pycatfile-0.13.2}/README.md +0 -0
- {pycatfile-0.12.8 → pycatfile-0.13.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyCatFile
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13.2
|
|
4
4
|
Summary: A tar like file format name catfile after unix cat command (concatenate files) .
|
|
5
5
|
Home-page: https://github.com/GameMaker2k/PyCatFile
|
|
6
6
|
Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyCatFile
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13.2
|
|
4
4
|
Summary: A tar like file format name catfile after unix cat command (concatenate files) .
|
|
5
5
|
Home-page: https://github.com/GameMaker2k/PyCatFile
|
|
6
6
|
Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
|
|
15
15
|
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
|
|
16
16
|
|
|
17
|
-
$FileInfo: catfile.py - Last Update: 6/
|
|
17
|
+
$FileInfo: catfile.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
|
|
18
18
|
'''
|
|
19
19
|
|
|
20
20
|
from __future__ import absolute_import, division, print_function, unicode_literals;
|
|
@@ -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: neocatfile.py - Last Update: 6/
|
|
17
|
+
$FileInfo: neocatfile.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
|
|
18
18
|
'''
|
|
19
19
|
|
|
20
20
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
|
|
15
15
|
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
|
|
16
16
|
|
|
17
|
-
$FileInfo: pycatfile.py - Last Update: 6/
|
|
17
|
+
$FileInfo: pycatfile.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
|
|
18
18
|
'''
|
|
19
19
|
|
|
20
20
|
from __future__ import absolute_import, division, print_function, unicode_literals;
|
|
@@ -157,43 +157,46 @@ except ImportError:
|
|
|
157
157
|
from StringIO import StringIO as BytesIO;
|
|
158
158
|
|
|
159
159
|
__use_pysftp__ = False;
|
|
160
|
+
__use_alt_format__ = False;
|
|
160
161
|
if(not havepysftp):
|
|
161
162
|
__use_pysftp__ = False;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
163
|
+
if(not __use_alt_format__):
|
|
164
|
+
''' Format Info by Kazuki Przyborowski '''
|
|
165
|
+
__file_format_name__ = "CatFile";
|
|
166
|
+
__program_name__ = "Py"+__file_format_name__;
|
|
167
|
+
__file_format_lower__ = __file_format_name__.lower();
|
|
168
|
+
__file_format_magic__ = __file_format_name__;
|
|
169
|
+
__file_format_len__ = len(__file_format_magic__);
|
|
170
|
+
__file_format_hex__ = binascii.hexlify(__file_format_magic__.encode("UTF-8")).decode("UTF-8");
|
|
171
|
+
__file_format_delimiter__ = "\x00";
|
|
172
|
+
__file_format_ver__ = "001";
|
|
173
|
+
__use_new_style__ = True;
|
|
174
|
+
__use_advanced_list__ = True;
|
|
175
|
+
__use_alt_inode__ = False;
|
|
176
|
+
__file_format_extension__ = ".cat";
|
|
177
|
+
else:
|
|
178
|
+
''' Format Info Generated by ChatGPT '''
|
|
179
|
+
__file_format_name__ = "FastArchive";
|
|
180
|
+
__program_name__ = "Py" + __file_format_name__;
|
|
181
|
+
__file_format_lower__ = __file_format_name__.lower();
|
|
182
|
+
__file_format_magic__ = "FstArch";
|
|
183
|
+
__file_format_len__ = len(__file_format_magic__);
|
|
184
|
+
__file_format_hex__ = binascii.hexlify(__file_format_magic__.encode("UTF-8")).decode("UTF-8");
|
|
185
|
+
__file_format_delimiter__ = "\x1F"; # Using a non-printable ASCII character as delimiter
|
|
186
|
+
__file_format_ver__ = "001";
|
|
187
|
+
__use_new_style__ = True;
|
|
188
|
+
__use_advanced_list__ = False;
|
|
189
|
+
__use_alt_inode__ = False;
|
|
190
|
+
__file_format_extension__ = ".fast";
|
|
188
191
|
__file_format_list__ = [__file_format_name__, __file_format_magic__, __file_format_lower__, __file_format_len__, __file_format_hex__, __file_format_delimiter__, __file_format_ver__, __use_new_style__, __use_advanced_list__, __use_alt_inode__];
|
|
189
192
|
__file_format_dict__ = {'format_name': __file_format_name__, 'format_magic': __file_format_magic__, 'format_lower': __file_format_lower__, 'format_len': __file_format_len__, 'format_hex': __file_format_hex__, 'format_delimiter': __file_format_delimiter__, 'format_ver': __file_format_ver__, 'new_style': __use_new_style__, 'use_advanced_list': __use_advanced_list__, 'use_alt_inode': __use_alt_inode__};
|
|
190
193
|
__project__ = __program_name__;
|
|
191
194
|
__project_url__ = "https://github.com/GameMaker2k/PyCatFile";
|
|
192
|
-
__version_info__ = (0,
|
|
193
|
-
__version_date_info__ = (2024, 6,
|
|
195
|
+
__version_info__ = (0, 13, 2, "RC 1", 1);
|
|
196
|
+
__version_date_info__ = (2024, 6, 14, "RC 1", 1);
|
|
194
197
|
__version_date__ = str(__version_date_info__[0]) + "." + str(__version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2);
|
|
195
198
|
__revision__ = __version_info__[3];
|
|
196
|
-
__revision_id__ = "$Id:
|
|
199
|
+
__revision_id__ = "$Id: 4fa12ed6c9a98672ea7ca68f9bff7b0f13f625d1 $";
|
|
197
200
|
if(__version_info__[4] is not None):
|
|
198
201
|
__version_date_plusrc__ = __version_date__ + "-" + str(__version_date_info__[4]);
|
|
199
202
|
if(__version_info__[4] is None):
|
|
@@ -265,6 +268,7 @@ except ImportError:
|
|
|
265
268
|
compressionsupport.append("xz");
|
|
266
269
|
except ImportError:
|
|
267
270
|
pass;
|
|
271
|
+
compressionsupport.append("zlib");
|
|
268
272
|
|
|
269
273
|
compressionlist = ['auto'];
|
|
270
274
|
compressionlistalt = [];
|
|
@@ -310,6 +314,15 @@ if('xz' in compressionsupport):
|
|
|
310
314
|
compressionlistalt.append('xz');
|
|
311
315
|
outextlist.append('xz');
|
|
312
316
|
outextlistwd.append('.xz');
|
|
317
|
+
if('zlib' in compressionsupport):
|
|
318
|
+
compressionlist.append('zlib');
|
|
319
|
+
compressionlistalt.append('zlib');
|
|
320
|
+
outextlist.append('zz');
|
|
321
|
+
outextlistwd.append('.zz');
|
|
322
|
+
outextlist.append('zl');
|
|
323
|
+
outextlistwd.append('.zl');
|
|
324
|
+
outextlist.append('zlib');
|
|
325
|
+
outextlistwd.append('.zlib');
|
|
313
326
|
|
|
314
327
|
tarfile_mimetype = "application/tar";
|
|
315
328
|
tarfile_tar_mimetype = tarfile_mimetype;
|
|
@@ -330,7 +343,10 @@ archivefile_zstandard_mimetype = "application/x-"+__file_format_dict__['format_l
|
|
|
330
343
|
archivefile_zstd_mimetype = archivefile_zstandard_mimetype;
|
|
331
344
|
archivefile_lzma_mimetype = "application/x-"+__file_format_dict__['format_lower']+"+lzma";
|
|
332
345
|
archivefile_xz_mimetype = "application/x-"+__file_format_dict__['format_lower']+"+xz";
|
|
333
|
-
|
|
346
|
+
archivefile_zlib_mimetype = "application/x-"+__file_format_dict__['format_lower']+"+zlib";
|
|
347
|
+
archivefile_zz_mimetype = archivefile_zlib_mimetype;
|
|
348
|
+
archivefile_zl_mimetype = archivefile_zlib_mimetype;
|
|
349
|
+
archivefile_extensions = [__file_format_extension__, __file_format_extension__+".gz", __file_format_extension__+".bz2", __file_format_extension__+".zst", __file_format_extension__+".lz4", __file_format_extension__+".lzo", __file_format_extension__+".lzop", __file_format_extension__+".lzma", __file_format_extension__+".xz", __file_format_extension__+".zz", __file_format_extension__+".zl", __file_format_extension__+".zlib"];
|
|
334
350
|
|
|
335
351
|
if __name__ == "__main__":
|
|
336
352
|
import subprocess;
|
|
@@ -510,6 +526,436 @@ def FormatSpecsListToDict(formatspecs=__file_format_list__):
|
|
|
510
526
|
return __file_format_dict__;
|
|
511
527
|
return __file_format_dict__;
|
|
512
528
|
|
|
529
|
+
class ZlibFile:
|
|
530
|
+
def __init__(self, file_path=None, fileobj=None, mode='rb', level=9, wbits=15, encoding=None, errors=None, newline=None):
|
|
531
|
+
if file_path is None and fileobj is None:
|
|
532
|
+
raise ValueError("Either file_path or fileobj must be provided");
|
|
533
|
+
if file_path is not None and fileobj is not None:
|
|
534
|
+
raise ValueError("Only one of file_path or fileobj should be provided");
|
|
535
|
+
|
|
536
|
+
self.file_path = file_path;
|
|
537
|
+
self.fileobj = fileobj;
|
|
538
|
+
self.mode = mode;
|
|
539
|
+
self.level = level;
|
|
540
|
+
self.wbits = wbits;
|
|
541
|
+
self.encoding = encoding;
|
|
542
|
+
self.errors = errors;
|
|
543
|
+
self.newline = newline;
|
|
544
|
+
self._compressed_data = b'';
|
|
545
|
+
self._decompressed_data = b'';
|
|
546
|
+
self._position = 0;
|
|
547
|
+
self._text_mode = 't' in mode;
|
|
548
|
+
|
|
549
|
+
# Force binary mode for internal handling
|
|
550
|
+
internal_mode = mode.replace('t', 'b');
|
|
551
|
+
|
|
552
|
+
if 'w' in mode or 'a' in mode or 'x' in mode:
|
|
553
|
+
self.file = open(file_path, internal_mode) if file_path else fileobj;
|
|
554
|
+
self._compressor = zlib.compressobj(level, zlib.DEFLATED, wbits);
|
|
555
|
+
elif 'r' in mode:
|
|
556
|
+
if file_path:
|
|
557
|
+
if os.path.exists(file_path):
|
|
558
|
+
self.file = open(file_path, internal_mode);
|
|
559
|
+
self._load_file();
|
|
560
|
+
else:
|
|
561
|
+
raise FileNotFoundError("No such file: '{}'".format(file_path));
|
|
562
|
+
elif fileobj:
|
|
563
|
+
self.file = fileobj;
|
|
564
|
+
self._load_file();
|
|
565
|
+
else:
|
|
566
|
+
raise ValueError("Mode should be 'rb' or 'wb'");
|
|
567
|
+
|
|
568
|
+
def _load_file(self):
|
|
569
|
+
self.file.seek(0);
|
|
570
|
+
self._compressed_data = self.file.read();
|
|
571
|
+
if not self._compressed_data.startswith((b'\x78\x01', b'\x78\x5E', b'\x78\x9C', b'\x78\xDA')):
|
|
572
|
+
raise ValueError("Invalid zlib file header");
|
|
573
|
+
self._decompressed_data = zlib.decompress(self._compressed_data, self.wbits);
|
|
574
|
+
if self._text_mode:
|
|
575
|
+
self._decompressed_data = self._decompressed_data.decode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
576
|
+
|
|
577
|
+
def write(self, data):
|
|
578
|
+
if self._text_mode:
|
|
579
|
+
data = data.encode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
580
|
+
compressed_data = self._compressor.compress(data) + self._compressor.flush(zlib.Z_SYNC_FLUSH);
|
|
581
|
+
self.file.write(compressed_data);
|
|
582
|
+
|
|
583
|
+
def read(self, size=-1):
|
|
584
|
+
if size == -1:
|
|
585
|
+
size = len(self._decompressed_data) - self._position;
|
|
586
|
+
data = self._decompressed_data[self._position:self._position + size];
|
|
587
|
+
self._position += size;
|
|
588
|
+
return data;
|
|
589
|
+
|
|
590
|
+
def seek(self, offset, whence=0):
|
|
591
|
+
if whence == 0: # absolute file positioning
|
|
592
|
+
self._position = offset;
|
|
593
|
+
elif whence == 1: # seek relative to the current position
|
|
594
|
+
self._position += offset;
|
|
595
|
+
elif whence == 2: # seek relative to the file's end
|
|
596
|
+
self._position = len(self._decompressed_data) + offset;
|
|
597
|
+
else:
|
|
598
|
+
raise ValueError("Invalid value for whence");
|
|
599
|
+
|
|
600
|
+
# Ensure the position is within bounds
|
|
601
|
+
self._position = max(0, min(self._position, len(self._decompressed_data)));
|
|
602
|
+
|
|
603
|
+
def tell(self):
|
|
604
|
+
return self._position;
|
|
605
|
+
|
|
606
|
+
def flush(self):
|
|
607
|
+
self.file.flush();
|
|
608
|
+
|
|
609
|
+
def fileno(self):
|
|
610
|
+
if hasattr(self.file, 'fileno'):
|
|
611
|
+
return self.file.fileno();
|
|
612
|
+
raise OSError("The underlying file object does not support fileno()");
|
|
613
|
+
|
|
614
|
+
def isatty(self):
|
|
615
|
+
if hasattr(self.file, 'isatty'):
|
|
616
|
+
return self.file.isatty();
|
|
617
|
+
return False;
|
|
618
|
+
|
|
619
|
+
def truncate(self, size=None):
|
|
620
|
+
if hasattr(self.file, 'truncate'):
|
|
621
|
+
return self.file.truncate(size);
|
|
622
|
+
raise OSError("The underlying file object does not support truncate()");
|
|
623
|
+
|
|
624
|
+
def close(self):
|
|
625
|
+
if 'w' in self.mode or 'a' in self.mode or 'x' in self.mode:
|
|
626
|
+
self.file.write(self._compressor.flush(zlib.Z_FINISH));
|
|
627
|
+
if self.file_path:
|
|
628
|
+
self.file.close();
|
|
629
|
+
|
|
630
|
+
def __enter__(self):
|
|
631
|
+
return self;
|
|
632
|
+
|
|
633
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
634
|
+
self.close();
|
|
635
|
+
|
|
636
|
+
class GzipFile:
|
|
637
|
+
def __init__(self, file_path=None, fileobj=None, mode='rb', compresslevel=9, encoding=None, errors=None, newline=None):
|
|
638
|
+
if file_path is None and fileobj is None:
|
|
639
|
+
raise ValueError("Either file_path or fileobj must be provided");
|
|
640
|
+
if file_path is not None and fileobj is not None:
|
|
641
|
+
raise ValueError("Only one of file_path or fileobj should be provided");
|
|
642
|
+
|
|
643
|
+
self.file_path = file_path;
|
|
644
|
+
self.fileobj = fileobj;
|
|
645
|
+
self.mode = mode;
|
|
646
|
+
self.compresslevel = compresslevel;
|
|
647
|
+
self.encoding = encoding;
|
|
648
|
+
self.errors = errors;
|
|
649
|
+
self.newline = newline;
|
|
650
|
+
self._compressed_data = b'';
|
|
651
|
+
self._decompressed_data = b'';
|
|
652
|
+
self._position = 0;
|
|
653
|
+
self._text_mode = 't' in mode;
|
|
654
|
+
|
|
655
|
+
# Force binary mode for internal handling
|
|
656
|
+
internal_mode = mode.replace('t', 'b');
|
|
657
|
+
|
|
658
|
+
if 'w' in mode or 'a' in mode or 'x' in mode:
|
|
659
|
+
self.file = gzip.open(file_path, internal_mode, compresslevel=compresslevel) if file_path else gzip.GzipFile(fileobj=fileobj, mode=internal_mode, compresslevel=compresslevel);
|
|
660
|
+
self._compressor = gzip.GzipFile(fileobj=self.file, mode=internal_mode, compresslevel=compresslevel);
|
|
661
|
+
elif 'r' in mode:
|
|
662
|
+
if file_path:
|
|
663
|
+
if os.path.exists(file_path):
|
|
664
|
+
self.file = gzip.open(file_path, internal_mode);
|
|
665
|
+
self._load_file();
|
|
666
|
+
else:
|
|
667
|
+
raise FileNotFoundError("No such file: '{}'".format(file_path));
|
|
668
|
+
elif fileobj:
|
|
669
|
+
self.file = gzip.GzipFile(fileobj=fileobj, mode=internal_mode);
|
|
670
|
+
self._load_file();
|
|
671
|
+
else:
|
|
672
|
+
raise ValueError("Mode should be 'rb' or 'wb'");
|
|
673
|
+
|
|
674
|
+
def _load_file(self):
|
|
675
|
+
self.file.seek(0);
|
|
676
|
+
self._compressed_data = self.file.read();
|
|
677
|
+
if not self._compressed_data.startswith(b'\x1f\x8b'):
|
|
678
|
+
raise ValueError("Invalid gzip file header");
|
|
679
|
+
self._decompressed_data = gzip.decompress(self._compressed_data);
|
|
680
|
+
if self._text_mode:
|
|
681
|
+
self._decompressed_data = self._decompressed_data.decode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
682
|
+
|
|
683
|
+
def write(self, data):
|
|
684
|
+
if self._text_mode:
|
|
685
|
+
data = data.encode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
686
|
+
compressed_data = self._compressor.compress(data);
|
|
687
|
+
self.file.write(compressed_data);
|
|
688
|
+
self.file.flush();
|
|
689
|
+
|
|
690
|
+
def read(self, size=-1):
|
|
691
|
+
if size == -1:
|
|
692
|
+
size = len(self._decompressed_data) - self._position;
|
|
693
|
+
data = self._decompressed_data[self._position:self._position + size];
|
|
694
|
+
self._position += size;
|
|
695
|
+
return data;
|
|
696
|
+
|
|
697
|
+
def seek(self, offset, whence=0):
|
|
698
|
+
if whence == 0: # absolute file positioning
|
|
699
|
+
self._position = offset;
|
|
700
|
+
elif whence == 1: # seek relative to the current position
|
|
701
|
+
self._position += offset;
|
|
702
|
+
elif whence == 2: # seek relative to the file's end
|
|
703
|
+
self._position = len(self._decompressed_data) + offset;
|
|
704
|
+
else:
|
|
705
|
+
raise ValueError("Invalid value for whence");
|
|
706
|
+
|
|
707
|
+
# Ensure the position is within bounds
|
|
708
|
+
self._position = max(0, min(self._position, len(self._decompressed_data)));
|
|
709
|
+
|
|
710
|
+
def tell(self):
|
|
711
|
+
return self._position;
|
|
712
|
+
|
|
713
|
+
def flush(self):
|
|
714
|
+
self.file.flush();
|
|
715
|
+
|
|
716
|
+
def fileno(self):
|
|
717
|
+
if hasattr(self.file, 'fileno'):
|
|
718
|
+
return self.file.fileno();
|
|
719
|
+
raise OSError("The underlying file object does not support fileno()");
|
|
720
|
+
|
|
721
|
+
def isatty(self):
|
|
722
|
+
if hasattr(self.file, 'isatty'):
|
|
723
|
+
return self.file.isatty();
|
|
724
|
+
return False;
|
|
725
|
+
|
|
726
|
+
def truncate(self, size=None):
|
|
727
|
+
if hasattr(self.file, 'truncate'):
|
|
728
|
+
return self.file.truncate(size);
|
|
729
|
+
raise OSError("The underlying file object does not support truncate()");
|
|
730
|
+
|
|
731
|
+
def close(self):
|
|
732
|
+
if 'w' in self.mode or 'a' in self.mode or 'x' in self.mode:
|
|
733
|
+
self.file.write(self._compressor.flush());
|
|
734
|
+
if self.file_path:
|
|
735
|
+
self.file.close();
|
|
736
|
+
|
|
737
|
+
def __enter__(self):
|
|
738
|
+
return self;
|
|
739
|
+
|
|
740
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
741
|
+
self.close();
|
|
742
|
+
|
|
743
|
+
'''
|
|
744
|
+
class BloscFile:
|
|
745
|
+
def __init__(self, file_path=None, fileobj=None, mode='rb', level=9, encoding=None, errors=None, newline=None):
|
|
746
|
+
if file_path is None and fileobj is None:
|
|
747
|
+
raise ValueError("Either file_path or fileobj must be provided");
|
|
748
|
+
if file_path is not None and fileobj is not None:
|
|
749
|
+
raise ValueError("Only one of file_path or fileobj should be provided");
|
|
750
|
+
|
|
751
|
+
self.file_path = file_path;
|
|
752
|
+
self.fileobj = fileobj;
|
|
753
|
+
self.mode = mode;
|
|
754
|
+
self.level = level;
|
|
755
|
+
self.encoding = encoding;
|
|
756
|
+
self.errors = errors;
|
|
757
|
+
self.newline = newline;
|
|
758
|
+
self._compressed_data = b'';
|
|
759
|
+
self._decompressed_data = b'';
|
|
760
|
+
self._position = 0;
|
|
761
|
+
self._text_mode = 't' in mode;
|
|
762
|
+
|
|
763
|
+
# Force binary mode for internal handling
|
|
764
|
+
internal_mode = mode.replace('t', 'b');
|
|
765
|
+
|
|
766
|
+
if 'w' in mode or 'a' in mode or 'x' in mode:
|
|
767
|
+
self.file = open(file_path, internal_mode) if file_path else fileobj;
|
|
768
|
+
self._compressor = blosc.Blosc(level);
|
|
769
|
+
elif 'r' in mode:
|
|
770
|
+
if file_path:
|
|
771
|
+
if os.path.exists(file_path):
|
|
772
|
+
self.file = open(file_path, internal_mode);
|
|
773
|
+
self._load_file();
|
|
774
|
+
else:
|
|
775
|
+
raise FileNotFoundError("No such file: '{}'".format(file_path));
|
|
776
|
+
elif fileobj:
|
|
777
|
+
self.file = fileobj;
|
|
778
|
+
self._load_file();
|
|
779
|
+
else:
|
|
780
|
+
raise ValueError("Mode should be 'rb' or 'wb'");
|
|
781
|
+
|
|
782
|
+
def _load_file(self):
|
|
783
|
+
self.file.seek(0);
|
|
784
|
+
self._compressed_data = self.file.read();
|
|
785
|
+
if not self._compressed_data:
|
|
786
|
+
raise ValueError("Invalid blosc file header");
|
|
787
|
+
self._decompressed_data = blosc.decompress(self._compressed_data);
|
|
788
|
+
if self._text_mode:
|
|
789
|
+
self._decompressed_data = self._decompressed_data.decode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
790
|
+
|
|
791
|
+
def write(self, data):
|
|
792
|
+
if self._text_mode:
|
|
793
|
+
data = data.encode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
794
|
+
compressed_data = blosc.compress(data, cname='blosclz', clevel=self.level);
|
|
795
|
+
self.file.write(compressed_data);
|
|
796
|
+
self.file.flush();
|
|
797
|
+
|
|
798
|
+
def read(self, size=-1):
|
|
799
|
+
if size == -1:
|
|
800
|
+
size = len(self._decompressed_data) - self._position;
|
|
801
|
+
data = self._decompressed_data[self._position:self._position + size];
|
|
802
|
+
self._position += size;
|
|
803
|
+
return data;
|
|
804
|
+
|
|
805
|
+
def seek(self, offset, whence=0):
|
|
806
|
+
if whence == 0: # absolute file positioning
|
|
807
|
+
self._position = offset;
|
|
808
|
+
elif whence == 1: # seek relative to the current position
|
|
809
|
+
self._position += offset;
|
|
810
|
+
elif whence == 2: # seek relative to the file's end
|
|
811
|
+
self._position = len(self._decompressed_data) + offset;
|
|
812
|
+
else:
|
|
813
|
+
raise ValueError("Invalid value for whence");
|
|
814
|
+
|
|
815
|
+
# Ensure the position is within bounds
|
|
816
|
+
self._position = max(0, min(self._position, len(self._decompressed_data)));
|
|
817
|
+
|
|
818
|
+
def tell(self):
|
|
819
|
+
return self._position;
|
|
820
|
+
|
|
821
|
+
def flush(self):
|
|
822
|
+
self.file.flush();
|
|
823
|
+
|
|
824
|
+
def fileno(self):
|
|
825
|
+
if hasattr(self.file, 'fileno'):
|
|
826
|
+
return self.file.fileno();
|
|
827
|
+
raise OSError("The underlying file object does not support fileno()");
|
|
828
|
+
|
|
829
|
+
def isatty(self):
|
|
830
|
+
if hasattr(self.file, 'isatty'):
|
|
831
|
+
return self.file.isatty();
|
|
832
|
+
return False;
|
|
833
|
+
|
|
834
|
+
def truncate(self, size=None):
|
|
835
|
+
if hasattr(self.file, 'truncate'):
|
|
836
|
+
return self.file.truncate(size);
|
|
837
|
+
raise OSError("The underlying file object does not support truncate()");
|
|
838
|
+
|
|
839
|
+
def close(self):
|
|
840
|
+
if 'w' in self.mode or 'a' in self.mode or 'x' in self.mode:
|
|
841
|
+
self.file.write(blosc.compress(self._compressor.flush(), cname='blosclz', clevel=self.level));
|
|
842
|
+
if self.file_path:
|
|
843
|
+
self.file.close();
|
|
844
|
+
|
|
845
|
+
def __enter__(self):
|
|
846
|
+
return self;
|
|
847
|
+
|
|
848
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
849
|
+
self.close();
|
|
850
|
+
|
|
851
|
+
class BrotliFile:
|
|
852
|
+
def __init__(self, file_path=None, fileobj=None, mode='rb', level=11, encoding=None, errors=None, newline=None):
|
|
853
|
+
if file_path is None and fileobj is None:
|
|
854
|
+
raise ValueError("Either file_path or fileobj must be provided");
|
|
855
|
+
if file_path is not None and fileobj is not None:
|
|
856
|
+
raise ValueError("Only one of file_path or fileobj should be provided");
|
|
857
|
+
|
|
858
|
+
self.file_path = file_path;
|
|
859
|
+
self.fileobj = fileobj;
|
|
860
|
+
self.mode = mode;
|
|
861
|
+
self.level = level;
|
|
862
|
+
self.encoding = encoding;
|
|
863
|
+
self.errors = errors;
|
|
864
|
+
self.newline = newline;
|
|
865
|
+
self._compressed_data = b'';
|
|
866
|
+
self._decompressed_data = b'';
|
|
867
|
+
self._position = 0;
|
|
868
|
+
self._text_mode = 't' in mode;
|
|
869
|
+
|
|
870
|
+
# Force binary mode for internal handling
|
|
871
|
+
internal_mode = mode.replace('t', 'b');
|
|
872
|
+
|
|
873
|
+
if 'w' in mode or 'a' in mode or 'x' in mode:
|
|
874
|
+
self.file = open(file_path, internal_mode) if file_path else fileobj;
|
|
875
|
+
self._compressor = brotli.Compressor(quality=self.level);
|
|
876
|
+
elif 'r' in mode:
|
|
877
|
+
if file_path:
|
|
878
|
+
if os.path.exists(file_path):
|
|
879
|
+
self.file = open(file_path, internal_mode);
|
|
880
|
+
self._load_file();
|
|
881
|
+
else:
|
|
882
|
+
raise FileNotFoundError("No such file: '{}'".format(file_path));
|
|
883
|
+
elif fileobj:
|
|
884
|
+
self.file = fileobj;
|
|
885
|
+
self._load_file();
|
|
886
|
+
else:
|
|
887
|
+
raise ValueError("Mode should be 'rb' or 'wb'");
|
|
888
|
+
|
|
889
|
+
def _load_file(self):
|
|
890
|
+
self.file.seek(0);
|
|
891
|
+
self._compressed_data = self.file.read();
|
|
892
|
+
if not self._compressed_data:
|
|
893
|
+
raise ValueError("Invalid brotli file header");
|
|
894
|
+
self._decompressed_data = brotli.decompress(self._compressed_data);
|
|
895
|
+
if self._text_mode:
|
|
896
|
+
self._decompressed_data = self._decompressed_data.decode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
897
|
+
|
|
898
|
+
def write(self, data):
|
|
899
|
+
if self._text_mode:
|
|
900
|
+
data = data.encode(self.encoding or 'utf-8', self.errors or 'strict');
|
|
901
|
+
compressed_data = self._compressor.process(data);
|
|
902
|
+
self.file.write(compressed_data);
|
|
903
|
+
self.file.flush();
|
|
904
|
+
|
|
905
|
+
def read(self, size=-1):
|
|
906
|
+
if size == -1:
|
|
907
|
+
size = len(self._decompressed_data) - self._position;
|
|
908
|
+
data = self._decompressed_data[self._position:self._position + size];
|
|
909
|
+
self._position += size;
|
|
910
|
+
return data;
|
|
911
|
+
|
|
912
|
+
def seek(self, offset, whence=0):
|
|
913
|
+
if whence == 0: # absolute file positioning
|
|
914
|
+
self._position = offset;
|
|
915
|
+
elif whence == 1: # seek relative to the current position
|
|
916
|
+
self._position += offset;
|
|
917
|
+
elif whence == 2: # seek relative to the file's end
|
|
918
|
+
self._position = len(self._decompressed_data) + offset;
|
|
919
|
+
else:
|
|
920
|
+
raise ValueError("Invalid value for whence");
|
|
921
|
+
|
|
922
|
+
# Ensure the position is within bounds
|
|
923
|
+
self._position = max(0, min(self._position, len(self._decompressed_data)));
|
|
924
|
+
|
|
925
|
+
def tell(self):
|
|
926
|
+
return self._position;
|
|
927
|
+
|
|
928
|
+
def flush(self):
|
|
929
|
+
self.file.flush();
|
|
930
|
+
|
|
931
|
+
def fileno(self):
|
|
932
|
+
if hasattr(self.file, 'fileno'):
|
|
933
|
+
return self.file.fileno();
|
|
934
|
+
raise OSError("The underlying file object does not support fileno()");
|
|
935
|
+
|
|
936
|
+
def isatty(self):
|
|
937
|
+
if hasattr(self.file, 'isatty'):
|
|
938
|
+
return self.file.isatty();
|
|
939
|
+
return False;
|
|
940
|
+
|
|
941
|
+
def truncate(self, size=None):
|
|
942
|
+
if hasattr(self.file, 'truncate'):
|
|
943
|
+
return self.file.truncate(size);
|
|
944
|
+
raise OSError("The underlying file object does not support truncate()");
|
|
945
|
+
|
|
946
|
+
def close(self):
|
|
947
|
+
if 'w' in self.mode or 'a' in self.mode or 'x' in self.mode:
|
|
948
|
+
self.file.write(self._compressor.finish());
|
|
949
|
+
if self.file_path:
|
|
950
|
+
self.file.close();
|
|
951
|
+
|
|
952
|
+
def __enter__(self):
|
|
953
|
+
return self;
|
|
954
|
+
|
|
955
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
956
|
+
self.close();
|
|
957
|
+
'''
|
|
958
|
+
|
|
513
959
|
def TarFileCheck(infile):
|
|
514
960
|
try:
|
|
515
961
|
if is_tarfile(infile):
|
|
@@ -1402,8 +1848,12 @@ def ReadInFileBySizeWithContentToArray(infile, seekstart=0, seekend=0, listonly=
|
|
|
1402
1848
|
compresscheck = "lz4";
|
|
1403
1849
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
1404
1850
|
compresscheck = "lzo";
|
|
1405
|
-
elif(fextname==".lzma"
|
|
1851
|
+
elif(fextname==".lzma"):
|
|
1406
1852
|
compresscheck = "lzma";
|
|
1853
|
+
elif(fextname==".xz"):
|
|
1854
|
+
compresscheck = "xz";
|
|
1855
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
1856
|
+
compresscheck = "zlib";
|
|
1407
1857
|
else:
|
|
1408
1858
|
return False;
|
|
1409
1859
|
if(not compresscheck):
|
|
@@ -1460,8 +1910,12 @@ def ReadInFileBySizeWithContentToList(infile, seekstart=0, seekend=0, listonly=F
|
|
|
1460
1910
|
compresscheck = "lz4";
|
|
1461
1911
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
1462
1912
|
compresscheck = "lzo";
|
|
1463
|
-
elif(fextname==".lzma"
|
|
1913
|
+
elif(fextname==".lzma"):
|
|
1464
1914
|
compresscheck = "lzma";
|
|
1915
|
+
elif(fextname==".xz"):
|
|
1916
|
+
compresscheck = "xz";
|
|
1917
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
1918
|
+
compresscheck = "zlib";
|
|
1465
1919
|
else:
|
|
1466
1920
|
return False;
|
|
1467
1921
|
if(not compresscheck):
|
|
@@ -2092,11 +2546,19 @@ def CheckCompressionType(infile, formatspecs=__file_format_dict__, closefp=True)
|
|
|
2092
2546
|
catfp = open(infile, "rb");
|
|
2093
2547
|
except FileNotFoundError:
|
|
2094
2548
|
return False;
|
|
2549
|
+
filetype = False;
|
|
2095
2550
|
catfp.seek(0, 0);
|
|
2096
2551
|
prefp = catfp.read(2);
|
|
2097
|
-
filetype = False;
|
|
2098
2552
|
if(prefp==binascii.unhexlify("1f8b")):
|
|
2099
2553
|
filetype = "gzip";
|
|
2554
|
+
if(prefp==binascii.unhexlify("7801")):
|
|
2555
|
+
filetype = "zlib";
|
|
2556
|
+
if(prefp==binascii.unhexlify("785e")):
|
|
2557
|
+
filetype = "zlib";
|
|
2558
|
+
if(prefp==binascii.unhexlify("789c")):
|
|
2559
|
+
filetype = "zlib";
|
|
2560
|
+
if(prefp==binascii.unhexlify("78da")):
|
|
2561
|
+
filetype = "zlib";
|
|
2100
2562
|
catfp.seek(0, 0);
|
|
2101
2563
|
prefp = catfp.read(3);
|
|
2102
2564
|
if(prefp==binascii.unhexlify("425a68")):
|
|
@@ -2144,7 +2606,7 @@ def CheckCompressionType(infile, formatspecs=__file_format_dict__, closefp=True)
|
|
|
2144
2606
|
if(prefp==binascii.unhexlify("7061785f676c6f62616c")):
|
|
2145
2607
|
filetype = "tarfile";
|
|
2146
2608
|
catfp.seek(0, 0);
|
|
2147
|
-
if(filetype=="gzip" or filetype=="bzip2" or filetype=="lzma" or filetype=="zstd" or filetype=="lz4"):
|
|
2609
|
+
if(filetype=="gzip" or filetype=="bzip2" or filetype=="lzma" or filetype=="zstd" or filetype=="lz4" or filetype=="zlib"):
|
|
2148
2610
|
if(TarFileCheck(catfp)):
|
|
2149
2611
|
filetype = "tarfile";
|
|
2150
2612
|
if(not filetype):
|
|
@@ -2174,6 +2636,8 @@ def GetCompressionMimeType(infile, formatspecs=__file_format_dict__):
|
|
|
2174
2636
|
compresscheck = CheckCompressionType(fp, formatspecs, False);
|
|
2175
2637
|
if(compresscheck=="gzip" or compresscheck=="gz"):
|
|
2176
2638
|
return archivefile_gzip_mimetype;
|
|
2639
|
+
if(compresscheck=="zlib" or (compresscheck=="zz" or compresscheck=="zl" or compresscheck=="zlib")):
|
|
2640
|
+
return archivefile_zlib_mimetype;
|
|
2177
2641
|
if(compresscheck=="bzip2" or compresscheck=="bz2"):
|
|
2178
2642
|
return archivefile_bzip2_mimetype;
|
|
2179
2643
|
if(compresscheck=="zstd" or compresscheck=="zstandard"):
|
|
@@ -2199,21 +2663,19 @@ def UncompressArchiveFile(fp, formatspecs=__file_format_dict__):
|
|
|
2199
2663
|
compresscheck = CheckCompressionType(fp, formatspecs, False);
|
|
2200
2664
|
if(compresscheck=="gzip" and compresscheck in compressionsupport):
|
|
2201
2665
|
catfp = gzip.GzipFile(fileobj=fp, mode="rb");
|
|
2202
|
-
|
|
2203
|
-
catfp =
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
catfp.
|
|
2208
|
-
|
|
2209
|
-
catfp = BytesIO();
|
|
2210
|
-
catfp.write(lz4.frame.decompress(fp.read()));
|
|
2211
|
-
if((compresscheck=="lzo" or compresscheck=="lzop") and compresscheck in compressionsupport):
|
|
2666
|
+
elif(compresscheck=="bzip2" and compresscheck in compressionsupport):
|
|
2667
|
+
catfp = bz2.BZ2File(fp);
|
|
2668
|
+
elif(compresscheck=="zstd" and compresscheck in compressionsupport):
|
|
2669
|
+
catfp = zstd.ZstdDecompressor().stream_reader(fp);
|
|
2670
|
+
elif(compresscheck=="lz4" and compresscheck in compressionsupport):
|
|
2671
|
+
catfp = lz4.frame.open_fp(fp, mode='rb');
|
|
2672
|
+
elif((compresscheck=="lzo" or compresscheck=="lzop") and compresscheck in compressionsupport):
|
|
2212
2673
|
catfp = BytesIO();
|
|
2213
2674
|
catfp.write(lzo.decompress(fp.read()));
|
|
2214
|
-
|
|
2215
|
-
catfp =
|
|
2216
|
-
|
|
2675
|
+
elif((compresscheck=="lzma" or compresscheck=="xz") and compresscheck in compressionsupport):
|
|
2676
|
+
catfp = lzma.LZMAFile(fp);
|
|
2677
|
+
elif(compresscheck=="zlib" and compresscheck in compressionsupport):
|
|
2678
|
+
catfp = ZlibFile(fileobj=fp, mode="rb");
|
|
2217
2679
|
if(compresscheck=="catfile" or compresscheck==formatspecs['format_lower']):
|
|
2218
2680
|
catfp = fp;
|
|
2219
2681
|
if(not compresscheck):
|
|
@@ -2275,6 +2737,8 @@ def UncompressFile(infile, formatspecs=__file_format_dict__, mode="rb"):
|
|
|
2275
2737
|
filefp = lzma.open(infile, mode, encoding="UTF-8");
|
|
2276
2738
|
except (ValueError, TypeError) as e:
|
|
2277
2739
|
filefp = lzma.open(infile, mode);
|
|
2740
|
+
if(compresscheck=="zlib" and compresscheck in compressionsupport):
|
|
2741
|
+
filefp = ZlibFile(infile, mode=mode);
|
|
2278
2742
|
if(compresscheck=="catfile" or compresscheck==formatspecs['format_lower']):
|
|
2279
2743
|
try:
|
|
2280
2744
|
filefp = open(infile, mode, encoding="UTF-8");
|
|
@@ -2287,6 +2751,10 @@ def UncompressFile(infile, formatspecs=__file_format_dict__, mode="rb"):
|
|
|
2287
2751
|
filefp = open(infile, mode);
|
|
2288
2752
|
except FileNotFoundError:
|
|
2289
2753
|
return False;
|
|
2754
|
+
try:
|
|
2755
|
+
filefp.write_through = True;
|
|
2756
|
+
except AttributeError:
|
|
2757
|
+
pass;
|
|
2290
2758
|
return filefp;
|
|
2291
2759
|
|
|
2292
2760
|
def UncompressString(infile):
|
|
@@ -2307,6 +2775,8 @@ def UncompressString(infile):
|
|
|
2307
2775
|
fileuz = lzo.decompress(infile);
|
|
2308
2776
|
if((compresscheck=="lzma" or compresscheck=="xz") and compresscheck in compressionsupport):
|
|
2309
2777
|
fileuz = lzma.decompress(infile);
|
|
2778
|
+
if(compresscheck=="zlib" and compresscheck in compressionsupport):
|
|
2779
|
+
fileuz = zlib.decompress(infile);
|
|
2310
2780
|
if(not compresscheck):
|
|
2311
2781
|
fileuz = infile;
|
|
2312
2782
|
if(hasattr(fileuz, 'decode')):
|
|
@@ -2335,11 +2805,15 @@ def CheckCompressionSubType(infile, formatspecs=__file_format_dict__, closefp=Tr
|
|
|
2335
2805
|
compresscheck = "lz4";
|
|
2336
2806
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
2337
2807
|
compresscheck = "lzo";
|
|
2338
|
-
elif(fextname==".lzma"
|
|
2339
|
-
|
|
2808
|
+
elif(fextname==".lzma"):
|
|
2809
|
+
compresscheck = "lzma";
|
|
2810
|
+
elif(fextname==".xz"):
|
|
2811
|
+
compresscheck = "xz";
|
|
2812
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
2813
|
+
compresscheck = "zlib";
|
|
2340
2814
|
else:
|
|
2341
2815
|
return False;
|
|
2342
|
-
if(compresscheck=="gzip" or compresscheck=="bzip2" or compresscheck=="lzma" or compresscheck=="zstd" or compresscheck=="lz4"):
|
|
2816
|
+
if(compresscheck=="gzip" or compresscheck=="bzip2" or compresscheck=="lzma" or compresscheck=="zstd" or compresscheck=="lz4" or compresscheck=="zlib"):
|
|
2343
2817
|
if(TarFileCheck(infile)):
|
|
2344
2818
|
filetype = "tarfile";
|
|
2345
2819
|
if(not compresscheck):
|
|
@@ -2370,16 +2844,20 @@ def CheckCompressionSubType(infile, formatspecs=__file_format_dict__, closefp=Tr
|
|
|
2370
2844
|
try:
|
|
2371
2845
|
if(compresscheck=="gzip" and compresscheck in compressionsupport):
|
|
2372
2846
|
catfp = gzip.GzipFile(infile, "rb");
|
|
2373
|
-
|
|
2847
|
+
elif(compresscheck=="bzip2" and compresscheck in compressionsupport):
|
|
2374
2848
|
catfp = bz2.BZ2File(infile, "rb");
|
|
2375
|
-
|
|
2849
|
+
elif(compresscheck=="lz4" and compresscheck in compressionsupport):
|
|
2376
2850
|
catfp = lz4.frame.open(infile, "rb");
|
|
2377
|
-
|
|
2851
|
+
elif(compresscheck=="zstd" and compresscheck in compressionsupport):
|
|
2378
2852
|
catfp = zstandard.open(infile, "rb");
|
|
2379
|
-
|
|
2853
|
+
elif((compresscheck=="lzo" or compresscheck=="lzop") and compresscheck in compressionsupport):
|
|
2380
2854
|
catfp = lzo.open(infile, "rb");
|
|
2381
|
-
|
|
2855
|
+
elif((compresscheck=="lzma" or compresscheck=="xz") and compresscheck in compressionsupport):
|
|
2382
2856
|
catfp = lzma.open(infile, "rb");
|
|
2857
|
+
elif(compresscheck=="zlib" and compresscheck in compressionsupport):
|
|
2858
|
+
catfp = ZlibFile(infile, mode="rb");
|
|
2859
|
+
else:
|
|
2860
|
+
catfp = open(infile, "rb");
|
|
2383
2861
|
except FileNotFoundError:
|
|
2384
2862
|
return False;
|
|
2385
2863
|
filetype = False;
|
|
@@ -2477,6 +2955,13 @@ def CompressArchiveFile(fp, compression="auto", compressionlevel=None, formatspe
|
|
|
2477
2955
|
else:
|
|
2478
2956
|
compressionlevel = int(compressionlevel);
|
|
2479
2957
|
catfp.write(lzma.compress(fp.read(), format=lzma.FORMAT_XZ, filters=[{"id": lzma.FILTER_LZMA2, "preset": compressionlevel}]));
|
|
2958
|
+
if(compression=="zlib" and compression in compressionsupport):
|
|
2959
|
+
catfp = BytesIO();
|
|
2960
|
+
if(compressionlevel is None):
|
|
2961
|
+
compressionlevel = 9;
|
|
2962
|
+
else:
|
|
2963
|
+
compressionlevel = int(compressionlevel);
|
|
2964
|
+
catfp.write(lzma.compress(fp.read(), level=compressionlevel));
|
|
2480
2965
|
if(compression=="auto" or compression is None):
|
|
2481
2966
|
catfp = fp;
|
|
2482
2967
|
catfp.seek(0, 0);
|
|
@@ -2540,8 +3025,14 @@ def CompressOpenFile(outfile, compressionenable=True, compressionlevel=None):
|
|
|
2540
3025
|
outfp = lzma.open(outfile, mode, format=lzma.FORMAT_ALONE, filters=[{"id": lzma.FILTER_LZMA1, "preset": compressionlevel}], encoding="UTF-8");
|
|
2541
3026
|
except (ValueError, TypeError) as e:
|
|
2542
3027
|
outfp = lzma.open(outfile, mode, format=lzma.FORMAT_ALONE, filters=[{"id": lzma.FILTER_LZMA1, "preset": compressionlevel}]);
|
|
3028
|
+
elif((fextname==".zz" or fextname==".zl" or fextname==".zlib") and "zlib" in compressionsupport):
|
|
3029
|
+
outfp = ZlibFile(outfile, mode=mode, level=compressionlevel);
|
|
2543
3030
|
except FileNotFoundError:
|
|
2544
3031
|
return False;
|
|
3032
|
+
try:
|
|
3033
|
+
outfp.write_through = True;
|
|
3034
|
+
except AttributeError:
|
|
3035
|
+
pass;
|
|
2545
3036
|
return outfp;
|
|
2546
3037
|
|
|
2547
3038
|
def GetDevMajorMinor(fdev):
|
|
@@ -2985,8 +3476,6 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
|
|
|
2985
3476
|
except AttributeError:
|
|
2986
3477
|
if(not TarFileCheck(infile)):
|
|
2987
3478
|
return False;
|
|
2988
|
-
else:
|
|
2989
|
-
return False;
|
|
2990
3479
|
try:
|
|
2991
3480
|
if(hasattr(infile, "read") or hasattr(infile, "write")):
|
|
2992
3481
|
tarfp = tarfile.open(fileobj=infile, mode="r");
|
|
@@ -3209,8 +3698,6 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
|
|
|
3209
3698
|
infile.seek(0, 0);
|
|
3210
3699
|
elif(not os.path.exists(infile) or not os.path.isfile(infile)):
|
|
3211
3700
|
return False;
|
|
3212
|
-
else:
|
|
3213
|
-
return False;
|
|
3214
3701
|
if(not zipfile.is_zipfile(infile)):
|
|
3215
3702
|
return False;
|
|
3216
3703
|
try:
|
|
@@ -3262,17 +3749,17 @@ def PackArchiveFileFromZipFile(infile, outfile, compression="auto", compresswhol
|
|
|
3262
3749
|
fwinattributes = format(int(zipinfo.external_attr), 'x').lower();
|
|
3263
3750
|
if(not member.is_dir()):
|
|
3264
3751
|
fmode = format(int(stat.S_IFREG + 438), 'x').lower();
|
|
3265
|
-
fchmode = stat.S_IMODE(
|
|
3266
|
-
ftypemod = stat.S_IFMT(
|
|
3752
|
+
fchmode = stat.S_IMODE(int(stat.S_IFREG + 438));
|
|
3753
|
+
ftypemod = stat.S_IFMT(int(stat.S_IFREG + 438));
|
|
3267
3754
|
elif(member.is_dir()):
|
|
3268
3755
|
fmode = format(int(stat.S_IFDIR + 511), 'x').lower();
|
|
3269
|
-
fchmode = stat.S_IMODE(
|
|
3270
|
-
ftypemod = stat.S_IFMT(
|
|
3756
|
+
fchmode = stat.S_IMODE(int(stat.S_IFDIR + 511));
|
|
3757
|
+
ftypemod = stat.S_IFMT(int(stat.S_IFDIR + 511));
|
|
3271
3758
|
elif(zipinfo.create_system==3):
|
|
3272
3759
|
fwinattributes = format(int(0), 'x').lower();
|
|
3273
3760
|
fmode = format(int(zipinfo.external_attr), 'x').lower();
|
|
3274
|
-
fchmode = stat.S_IMODE(
|
|
3275
|
-
ftypemod = stat.S_IFMT(
|
|
3761
|
+
fchmode = stat.S_IMODE(int(zipinfo.external_attr));
|
|
3762
|
+
ftypemod = stat.S_IFMT(int(zipinfo.external_attr));
|
|
3276
3763
|
else:
|
|
3277
3764
|
fwinattributes = format(int(0), 'x').lower();
|
|
3278
3765
|
if(not member.is_dir()):
|
|
@@ -3973,8 +4460,12 @@ def ArchiveFileSeekToFileNum(infile, seekto=0, listonly=False, skipchecksum=Fals
|
|
|
3973
4460
|
compresscheck = "lz4";
|
|
3974
4461
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
3975
4462
|
compresscheck = "lzo";
|
|
3976
|
-
elif(fextname==".lzma"
|
|
4463
|
+
elif(fextname==".lzma"):
|
|
3977
4464
|
compresscheck = "lzma";
|
|
4465
|
+
elif(fextname==".xz"):
|
|
4466
|
+
compresscheck = "xz";
|
|
4467
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
4468
|
+
compresscheck = "zlib";
|
|
3978
4469
|
else:
|
|
3979
4470
|
return False;
|
|
3980
4471
|
if(not compresscheck):
|
|
@@ -4202,8 +4693,12 @@ def ArchiveFileSeekToFileName(infile, seekfile=None, listonly=False, skipchecksu
|
|
|
4202
4693
|
compresscheck = "lz4";
|
|
4203
4694
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
4204
4695
|
compresscheck = "lzo";
|
|
4205
|
-
elif(fextname==".lzma"
|
|
4696
|
+
elif(fextname==".lzma"):
|
|
4206
4697
|
compresscheck = "lzma";
|
|
4698
|
+
elif(fextname==".xz"):
|
|
4699
|
+
compresscheck = "xz";
|
|
4700
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
4701
|
+
compresscheck = "zlib";
|
|
4207
4702
|
else:
|
|
4208
4703
|
return False;
|
|
4209
4704
|
if(not compresscheck):
|
|
@@ -4443,8 +4938,12 @@ def ArchiveFileValidate(infile, formatspecs=__file_format_dict__, verbose=False,
|
|
|
4443
4938
|
compresscheck = "lz4";
|
|
4444
4939
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
4445
4940
|
compresscheck = "lzo";
|
|
4446
|
-
elif(fextname==".lzma"
|
|
4941
|
+
elif(fextname==".lzma"):
|
|
4447
4942
|
compresscheck = "lzma";
|
|
4943
|
+
elif(fextname==".xz"):
|
|
4944
|
+
compresscheck = "xz";
|
|
4945
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
4946
|
+
compresscheck = "zlib";
|
|
4448
4947
|
else:
|
|
4449
4948
|
return False;
|
|
4450
4949
|
if(not compresscheck):
|
|
@@ -4683,8 +5182,12 @@ def ArchiveFileToArray(infile, seekstart=0, seekend=0, listonly=False, uncompres
|
|
|
4683
5182
|
compresscheck = "lz4";
|
|
4684
5183
|
elif(fextname==".lzo" or fextname==".lzop"):
|
|
4685
5184
|
compresscheck = "lzo";
|
|
4686
|
-
elif(fextname==".lzma"
|
|
5185
|
+
elif(fextname==".lzma"):
|
|
4687
5186
|
compresscheck = "lzma";
|
|
5187
|
+
elif(fextname==".xz"):
|
|
5188
|
+
compresscheck = "xz";
|
|
5189
|
+
elif(fextname==".zz" or fextname==".zl" or fextname==".zlib"):
|
|
5190
|
+
compresscheck = "zlib";
|
|
4688
5191
|
else:
|
|
4689
5192
|
return False;
|
|
4690
5193
|
if(not compresscheck):
|
|
@@ -5257,8 +5760,6 @@ def TarFileToArrayAlt(infile, listonly=False, checksumtype="crc32", extradata=[]
|
|
|
5257
5760
|
except AttributeError:
|
|
5258
5761
|
if(not TarFileCheck(infile)):
|
|
5259
5762
|
return False;
|
|
5260
|
-
else:
|
|
5261
|
-
return False;
|
|
5262
5763
|
try:
|
|
5263
5764
|
if(hasattr(infile, "read") or hasattr(infile, "write")):
|
|
5264
5765
|
tarfp = tarfile.open(fileobj=infile, mode="r");
|
|
@@ -5438,8 +5939,6 @@ def ZipFileToArrayAlt(infile, listonly=False, checksumtype="crc32", extradata=[]
|
|
|
5438
5939
|
infile.seek(0, 0);
|
|
5439
5940
|
elif(not os.path.exists(infile) or not os.path.isfile(infile)):
|
|
5440
5941
|
return False;
|
|
5441
|
-
else:
|
|
5442
|
-
return False;
|
|
5443
5942
|
if(not zipfile.is_zipfile(infile)):
|
|
5444
5943
|
return False;
|
|
5445
5944
|
try:
|
|
@@ -6641,8 +7140,6 @@ def TarFileListFiles(infile, verbose=False, returnfp=False):
|
|
|
6641
7140
|
except AttributeError:
|
|
6642
7141
|
if(not TarFileCheck(infile)):
|
|
6643
7142
|
return False;
|
|
6644
|
-
else:
|
|
6645
|
-
return False;
|
|
6646
7143
|
try:
|
|
6647
7144
|
if(hasattr(infile, "read") or hasattr(infile, "write")):
|
|
6648
7145
|
tarfp = tarfile.open(fileobj=infile, mode="r");
|
|
@@ -6727,14 +7224,12 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
|
|
|
6727
7224
|
infile.seek(0, 0);
|
|
6728
7225
|
elif(not os.path.exists(infile) or not os.path.isfile(infile)):
|
|
6729
7226
|
return False;
|
|
6730
|
-
else:
|
|
6731
|
-
return False;
|
|
6732
7227
|
if(not zipfile.is_zipfile(infile)):
|
|
6733
7228
|
return False;
|
|
6734
7229
|
try:
|
|
6735
7230
|
zipfp = zipfile.ZipFile(infile, "r", allowZip64=True);
|
|
6736
7231
|
except FileNotFoundError:
|
|
6737
|
-
return False;
|
|
7232
|
+
print(6);return False;
|
|
6738
7233
|
lcfi = 0;
|
|
6739
7234
|
returnval = {};
|
|
6740
7235
|
ziptest = zipfp.testzip();
|
|
@@ -6831,9 +7326,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
|
|
|
6831
7326
|
|
|
6832
7327
|
if(not rarfile_support):
|
|
6833
7328
|
def RarFileListFiles(infile, verbose=False, returnfp=False):
|
|
6834
|
-
|
|
6835
|
-
if(not os.path.exists(infile) or not os.path.isfile(infile)):
|
|
6836
|
-
return False;
|
|
7329
|
+
return False;
|
|
6837
7330
|
|
|
6838
7331
|
if(rarfile_support):
|
|
6839
7332
|
def RarFileListFiles(infile, verbose=False, returnfp=False):
|
|
@@ -6966,9 +7459,7 @@ if(rarfile_support):
|
|
|
6966
7459
|
|
|
6967
7460
|
if(not py7zr_support):
|
|
6968
7461
|
def SevenZipFileListFiles(infile, verbose=False, returnfp=False):
|
|
6969
|
-
|
|
6970
|
-
if(not os.path.exists(infile) or not os.path.isfile(infile)):
|
|
6971
|
-
return False;
|
|
7462
|
+
return False;
|
|
6972
7463
|
|
|
6973
7464
|
if(py7zr_support):
|
|
6974
7465
|
def SevenZipFileListFiles(infile, verbose=False, returnfp=False):
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
Copyright 2016-2024 Game Maker 2k - http://intdb.sourceforge.net/
|
|
14
14
|
Copyright 2016-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
|
|
15
15
|
|
|
16
|
-
$FileInfo: setup.py - Last Update: 6/
|
|
16
|
+
$FileInfo: setup.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
|
|
17
17
|
'''
|
|
18
18
|
|
|
19
19
|
import os, re, sys, pkg_resources;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|