Pkg.AD1 — API for parsing AD1 files¶
Overview¶
The Pkg.AD1 module contains the API for parsing AccessData Custom Content Image (AD1) files.
Parsing an AD1 Image¶
The following code example demonstrates how to parse an AD1 image and iterate its entries:
from Pro.Core import *
from Pkg.AD1 import *
def parseAD1(fname):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = AD1Object()
if not obj.Load(c) or not obj.Parse():
return
for e in obj:
# skip directories
if e.type == 5:
continue
print(e.GetTypeName(), e.GetFullPath())
Extracting File Content¶
The following code example demonstrates how to extract the decompressed content of an entry:
from Pro.Core import *
from Pkg.AD1 import *
def extractAD1Entry(fname, target_path):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = AD1Object()
if not obj.Load(c) or not obj.Parse():
return
for e in obj:
if e.type != 0:
continue
if e.GetFullPath() == target_path:
data = obj.GetEntryData(e)
if not data.isNull():
print("size:", data.size())
break
Module API¶
Pkg.AD1 module API.
Classes:
This class represents an opaque handle to the compressed content of an entry inside an AD1 image.
AD1Entry()This class represents a single entry (file, directory or symbolic link) in an AD1 image.
This class represents an AccessData Custom Content Image (AD1) file.
- class AD1ContentHandle¶
This class represents an opaque handle to the compressed content of an entry inside an AD1 image.
Instances are produced by the parser and passed back to
AD1Object.GetEntryData()to read the decompressed data. The handle has no user-serviceable fields.
- class AD1Entry¶
This class represents a single entry (file, directory or symbolic link) in an AD1 image.
Methods:
Returns the full path of the entry, joining
parent_pathandfilename.Returns a human-readable name for
type.Attributes:
The opaque handle to the entry content, or
Noneif the entry has no content (e.g.The entry base name.
The raw metadata dictionary, keyed by category and then by key.
The parent directory path, using the reader separator.
The entry type code.
- GetFullPath() → str¶
Returns the full path of the entry, joining
parent_pathandfilename.
- Returns
Returns the full path.
- Return type
str
- GetTypeName() → str¶
Returns a human-readable name for
type.
- Returns
Returns
"File","SymLink","Directory", or"Unknown: <n>".- Return type
str
- content_handle: Optional[Pkg.AD1.AD1ContentHandle]¶
The opaque handle to the entry content, or
Noneif the entry has no content (e.g. a directory).
- filename: str¶
The entry base name.
- metadata: Dict[int, Dict[int, bytes]]¶
The raw metadata dictionary, keyed by category and then by key. Values are the raw bytes stored in the image.
- parent_path: str¶
The parent directory path, using the reader separator. Empty string for entries in the image root.
- type: int¶
The entry type code.
0for a file,1for a symbolic link,5for a directory.
- class AD1Object¶
Bases:
Pro.Core.CFFObjectThis class represents an AccessData Custom Content Image (AD1) file.
Iterating over the object yields
AD1Entryinstances for every file, directory and symbolic link in the image.Methods:
GetEntryData(e, *[, wo, stream])Retrieves the decompressed content of an entry.
Parse()Parses the AD1 image header.
Attributes:
When
True(default), parsing and read errors are printed to standard output instead of being silently swallowed.
- GetEntryData(e: Pkg.AD1.AD1Entry, *, wo: Optional[Pro.Core.NTIWait] = None, stream: Optional[Pro.Core.NTContainer] = None) → Pro.Core.NTContainer¶
Retrieves the decompressed content of an entry.
- Parameters
e (AD1Entry) – The entry to read.
wo (Optional[NTIWait]) – Optional wait object for long-running operations. The read aborts early if the wait object is aborted.
stream (Optional[NTContainer]) – Optional destination container. When provided, decompressed data is appended to it and the same container is returned; otherwise a new resizable container is created.
- Returns
Returns the container holding the decompressed content, or an invalid container on error.
- Return type
- Parse() → bool¶
Parses the AD1 image header.
- Returns
Returns
Trueif successful; otherwise returnsFalse.- Return type
bool
- verbose: bool¶
When
True(default), parsing and read errors are printed to standard output instead of being silently swallowed.