Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pannal
Last active April 6, 2018 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pannal/d7e0cb3f64c712c0be8eef1719257ded to your computer and use it in GitHub Desktop.
Save pannal/d7e0cb3f64c712c0be8eef1719257ded to your computer and use it in GitHub Desktop.
Workaround for RarFile.read() with certain unrar versions
# 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