Last active
April 6, 2018 15:14
-
-
Save pannal/d7e0cb3f64c712c0be8eef1719257ded to your computer and use it in GitHub Desktop.
Workaround for RarFile.read() with certain unrar versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from rarfile import RarFile as _RarFile, UNRAR_TOOL, ORIG_OPEN_ARGS as OPEN_ARGS, custom_popen, check_returncode, \ | |
XTempFile, add_password_arg | |
class RarFile(_RarFile): | |
def read(self, fname, psw=None): | |
""" | |
read specific content of rarfile without parsing | |
:param fname: | |
:param psw: | |
:return: | |
""" | |
cmd = [UNRAR_TOOL] + list(OPEN_ARGS) | |
add_password_arg(cmd, self._password) | |
with XTempFile(self._rarfile) as rf: | |
p = custom_popen(cmd + [rf, fname]) | |
output = p.communicate()[0] | |
check_returncode(p, output) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment