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:

AD1ContentHandle()

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.

AD1Object()

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:

GetFullPath()

Returns the full path of the entry, joining parent_path and filename.

GetTypeName()

Returns a human-readable name for type.

Attributes:

content_handle

The opaque handle to the entry content, or None if the entry has no content (e.g.

filename

The entry base name.

metadata

The raw metadata dictionary, keyed by category and then by key.

parent_path

The parent directory path, using the reader separator.

type

The entry type code.

GetFullPath()str

Returns the full path of the entry, joining parent_path and filename.

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 None if 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. 0 for a file, 1 for a symbolic link, 5 for a directory.

class AD1Object

Bases: Pro.Core.CFFObject

This class represents an AccessData Custom Content Image (AD1) file.

Iterating over the object yields AD1Entry instances 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:

verbose

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

NTContainer

Parse()bool

Parses the AD1 image header.

Returns

Returns True if successful; otherwise returns False.

Return type

bool

verbose: bool

When True (default), parsing and read errors are printed to standard output instead of being silently swallowed.