pythonrar

How to determine if RarInfo is belong to more than one part using python rarfile?


When reading a multipart rar file using python rarfile, calling infolist() returns RarInfo objects for all files/directories in archive. Using volume property, one can determine which part a particular RarInfo object's start bytes is belong to; but I can't find a property that shows the part which that object is ending on. so how to determine if a RarInfo object is belonged to more than one part?


Solution

  • While there could be a property or method in rarfile module which I'm not aware of, But I did what I was up to using unrar.exe & subprocces:

    from subprocess import Popen, PIPE
    p = Popen(['unrar.exe', 'lb', <RAR FILE NAME PART X>], stdin=PIPE, stdout=PIPE, stderr=PIPE)
    output, err = p.communicate(b"input data that is passed to subprocess' stdin")
    rc = p.returncode
    output = output.decode("utf-8").split('\r\n')[:-1]
    

    running this for each part, gives you a list of file names contained in each part, then you can loop through them to find which files appeared in more than one part!


    NOTE: I've used unrar.exe delivered by WinRAR, available on it's installation directory; Adding that directory to system PATH will result in using just unrar.exe in Popen.