Pkg.TAR — API for parsing TAR archives

Overview

The Pkg.TAR module contains the API for parsing TAR archives.

Parsing a TAR Archive

The following code example demonstrates how to parse a TAR archive:

from Pro.Core import *
from Pkg.TAR import *

def parseTARArchive(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = TARObject()
    if not obj.Load(c) or not obj.ParseArchive():
        return
    curoffs = None
    while True:
        entry, curoffs = obj.NextEntry(curoffs)
        if entry == None:
            break
        # skip directories
        if obj.IsDirectory(entry):
            continue
        print("file name:", entry.name, "file offset:", str(entry.offset_data), "file size:", str(entry.size))
        # retrieves the file data as NTContainer
        fc = obj.GetEntryData(entry)

Module API

Pkg.TAR module API.

Classes:

TARObject()

This class represents a TAR archive.

class TARObject

Bases: Pro.Core.CFFObject

This class represents a TAR archive.

Methods:

DumpEntry(entry, out)

Dumps information about an entry to a text stream.

GetEntry(offset)

Retrieves an entry by its offset.

GetEntryData(entry)

Retrieves the data of an entry.

IsDirectory(entry)

Checks whether an entry is a directory.

NextEntry([curoffs])

Iterates over the entries.

ParseArchive()

Parses the archive.

DumpEntry(entry: Any, out: Pro.Core.NTTextStream)None

Dumps information about an entry to a text stream.

Parameters
  • entry (Any) – The entry.

  • out (NTTextStream) – The output text stream.

GetEntry(offset: int)Any

Retrieves an entry by its offset.

Parameters

offset (int) – The entry offset.

Returns

Returns a the entry if successful; otherwise returns None.

See also NextEntry().

GetEntryData(entry: Any)Pro.Core.NTContainer

Retrieves the data of an entry.

Parameters

entry (Any) – The entry.

Returns

Returns the data if successful; otherwise returns an invalid container.

Return type

NTContainer

See also NextEntry() and GetEntry().

IsDirectory(entry: Any)bool

Checks whether an entry is a directory.

Parameters

entry (Any) – The entry.

Returns

Returns True if the entry is a directory; otherwise returns False.

Return type

bool

See also NextEntry() and GetEntry().

NextEntry(curoffs: Optional[int] = None)Tuple[Any, int]

Iterates over the entries.

Parameters

curoffs (Optional[int]) – The current offset.

Returns

Returns a tuple containing the next entry and its offset if successful; otherwise returns a tuple containing two None values.

Return type

Tuple[Any, int]

See also GetEntry().

ParseArchive()bool

Parses the archive.

Returns

Returns True if successful; otherwise returns False.

Return type

bool