Esempio n. 1
0
def is_rarfile(filename):
    """Return true if file is a valid RAR file."""
    mode = constants.RAR_OM_LIST_INCSPLIT
    archive = unrarlib.RAROpenArchiveDataEx(filename, mode=mode)
    try:
        handle = unrarlib.RAROpenArchiveEx(ctypes.byref(archive))
    except unrarlib.UnrarException:
        return False
    unrarlib.RARCloseArchive(handle)
    return (archive.OpenResult == constants.SUCCESS)
Esempio n. 2
0
 def _close(self, handle):
     """Close RAR archive file."""
     try:
         unrarlib.RARCloseArchive(handle)
     except unrarlib.UnrarException:
         raise BadRarFile("RAR archive close error.")