Pkg.SevenZip — API for parsing 7z archives¶
Overview¶
The Pkg.SevenZip module contains the API for parsing 7z archives.
Parsing a 7z Archive¶
The following code example demonstrates how to parse a 7z archive:
from Pro.Core import *
from Pkg.SevenZip import *
def parse7zArchive(fname):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = SevenZipObject()
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
if obj.IsDirectory(entry):
continue
print("file name:", entry.filename)
# retrieves the file data as NTContainer
fc = obj.GetEntryData(entry)
Module API¶
Pkg.SevenZip module API.
Classes:
This class represents a 7z archive.
- class SevenZipObject¶
Bases:
Pro.Core.CFFObjectThis class represents a 7z archive.
Methods:
DumpEntry(i, out)Dumps information about an entry to a text stream.
GetEntry(i)Retrieves an entry by its index.
Returns the number of entries present in the archive.
GetEntryData(i)Retrieves the data of an entry.
IsDirectory(i)Checks whether an entry is a directory.
Parses the archive.
- DumpEntry(i: int, out: Pro.Core.NTTextStream) → None¶
Dumps information about an entry to a text stream.
- Parameters
i (int) – The entry index.
out (NTTextStream) – The output text stream.
- 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) → Pro.Core.NTContainer¶
Retrieves the data of an entry.
- Parameters
i (int) – The entry index.
- 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
Trueif the entry is a directory; otherwise returnsFalse.- Return type
bool
- ParseArchive() → bool¶
Parses the archive.
- Returns
Returns
Trueif successful; otherwise returnsFalse.- Return type
bool