Pkg.RAR
— API for parsing RAR archives¶
Parsing a RAR Archive¶
The following code example demonstrates how to parse a RAR archive:
from Pro.Core import *
from Pkg.RAR import *
def parseRARArchive(fname):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = RARObject()
if not obj.Load(c) or not obj.ParseArchive():
return
n = obj.GetEntryCount()
print(n)
for i in range(n):
entry = obj.GetEntry(i)
if entry == None:
break
# skip directories and symbolic links
if not obj.IsFile(entry):
continue
print("file name:", entry.filename)
# retrieves the file data as NTContainer
fc = obj.GetEntryData(entry)
Module API¶
Pkg.RAR module API.
Classes:
This class represents a RAR archive.
- class RARObject¶
Bases:
Pro.Core.CFFObject
This class represents a RAR archive.
Methods:
DumpEntry
(i, out)Dumps the information about an entry to a text stream.
Returns the computed end offset of the archive.
GetEntry
(i)Retrieves an entry by its index.
Returns the number of entries present in the archive.
GetEntryData
(i[, wo, password])Retrieves the data of an entry.
IsDirectory
(i)Checks whether an entry is a directory.
IsFile
(i)Checks whether an entry is a file.
IsSymLink
(i)Checks whether an entry is a symbolic link.
ParseArchive
([password])Parses the archive.
- DumpEntry(i: int, out: Pro.Core.NTTextStream) → None¶
Dumps the information about an entry to a text stream.
- Parameters
i (int) – The entry index.
out (NTTextStream) – The output text stream.
- GetEndOffset() → int¶
- Returns
Returns the computed end offset of the archive.
- Return type
int
- GetEntry(i: int) → Any¶
Retrieves an entry by its index.
- Parameters
i (int) – The entry index.
- Returns
Returns the requested entry if successful; otherwise returns
None
.- Return type
Any
See also
GetEntryCount()
.
- GetEntryCount() → int¶
- Returns
Returns the number of entries present in the archive.
- Return type
int
See also
GetEntry()
.
- GetEntryData(i: int, wo: Optional[Pro.Core.NTIWait] = None, password: Optional[bytes] = None) → Pro.Core.NTContainer¶
Retrieves the data of an entry.
- Parameters
i (int) – The entry index.
wo (NTIWait) – Optional wait object for the operation.
password (bytes) – Optional password to decrypt the data.
- Returns
Returns the data if successful; otherwise returns an invalid container.
- Return type
See also
GetEntryCount()
.
- IsDirectory(i: int) → bool¶
Checks whether an entry is a directory.
- Parameters
i (int) – The entry index.
- Returns
Returns
True
if the entry is a directory; otherwise returnsFalse
.- Return type
bool
See also
IsFile()
andIsSymLink()
.
- IsFile(i: int) → bool¶
Checks whether an entry is a file.
- Parameters
i (int) – The entry index.
- Returns
Returns
True
if the entry is a file; otherwise returnsFalse
.- Return type
bool
See also
IsDirectory()
andIsSymLink()
.
- IsSymLink(i: int) → bool¶
Checks whether an entry is a symbolic link.
- Parameters
i (int) – The entry index.
- Returns
Returns
True
if the entry is a symbolic link; otherwise returnsFalse
.- Return type
bool
See also
IsFile()
andIsDirectory()
.
- ParseArchive(password: Optional[bytes] = None) → bool¶
Parses the archive.
- Parameters
password (bytes) – An optional password to decrypt the archive.
- Returns
Returns
True
if successful; otherwise returnsFalse
.- Return type
bool