From 8d87511e8f1e4fcf130f4f111742701f284afcfc Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Sun, 31 Mar 2024 23:26:44 +0300 Subject: [PATCH] Add RarFile.is_solid() Fixes: #101 --- rarfile.py | 13 +++++++++++++ test/files/rar3-solid.rar | Bin 0 -> 221 bytes test/files/rar3-solid.rar.exp | 13 +++++++++++++ test/test_api.py | 11 +++++++++++ 4 files changed, 37 insertions(+) create mode 100644 test/files/rar3-solid.rar create mode 100644 test/files/rar3-solid.rar.exp diff --git a/rarfile.py b/rarfile.py index c18b34a..478a2be 100644 --- a/rarfile.py +++ b/rarfile.py @@ -739,6 +739,11 @@ class RarFile: """ return self._file_parser.needs_password() + def is_solid(self): + """Returns True if archive uses solid compression. + """ + return self._file_parser.is_solid() + def namelist(self): """Return list of filenames in archive. """ @@ -1030,6 +1035,14 @@ class CommonParser: self._sfx_offset = sfx_offset self._part_only = part_only + def is_solid(self): + """Returns True if archive uses solid compression. + """ + if self._main: + if self._main.flags & RAR_MAIN_SOLID: + return True + return False + def has_header_encryption(self): """Returns True if headers are encrypted """ diff --git a/test/files/rar3-solid.rar b/test/files/rar3-solid.rar new file mode 100644 index 0000000000000000000000000000000000000000..7af51ae1ebf29875c3a7cf04c1f527f04ba44b9b GIT binary patch literal 221 zcwP%iEK-zWXRy9d%)!9R00G)2B@GjF7-B$d4h9D1MbEY$-H>+1PS%)o*!}y?e(!1Z=WEnUV7&tm! zR`6WnVNbMjtnl8PH$RB$)+u#|UC+5wx{?Zi?_iiXFF^lB=>K2GB3{2fa=oK2WLmqt q@0*)qB@=+|;KS<!TGXMZkRaM0R literal 0 HcwPel00001 diff --git a/test/files/rar3-solid.rar.exp b/test/files/rar3-solid.rar.exp new file mode 100644 index 0000000..d1fb063 --- /dev/null +++ b/test/files/rar3-solid.rar.exp @@ -0,0 +1,13 @@ +Archive: test/files/rar3-solid.rar +FILE: hdrlen=44 datlen=92 is=F-- + flags=0x9080:EXTTIME,LONG,D1024 + os=3:UNIX ver=29 mode=-rw-r--r-- meth=3 cmp=92 dec=2048 vol=0 + crc=0xc5b7e6a2 (3317163682) date_time=2011-06-12 12:53:33 + name=stest1.txt + mtime=2011-06-12T12:53:33 +FILE: hdrlen=44 datlen=14 is=F-- + flags=0x9090:SOLID,EXTTIME,LONG,D1024 + os=3:UNIX ver=29 mode=-rw-r--r-- meth=3 cmp=14 dec=2048 vol=0 + crc=0xc5b7e6a2 (3317163682) date_time=2011-06-12 12:53:33 + name=stest2.txt + mtime=2011-06-12T12:53:33 diff --git a/test/test_api.py b/test/test_api.py index c1c24a2..e4cd570 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -383,3 +383,14 @@ def test_volume_info(): with rarfile.RarFile("test/files/rar5-vols.part1.rar", info_callback=info_cb) as rf: assert len(info_list) == 16 + +def test_is_solid(): + with rarfile.RarFile("test/files/rar3-comment-plain.rar") as rf: + assert not rf.is_solid() + with rarfile.RarFile("test/files/rar3-solid.rar") as rf: + assert rf.is_solid() + with rarfile.RarFile("test/files/rar5-crc.rar") as rf: + assert not rf.is_solid() + with rarfile.RarFile("test/files/rar5-solid.rar") as rf: + assert rf.is_solid() + -- 2.11.4.GIT