4.22. mayaiff — Reading Maya IFF files

This module contains the IFFReader class which can be used as a base class for reading Maya IFF files. The class parses the structure of the file and invokes a callback method for every chunk found in the file. The actual decoding of the chunk data has to be done in a derived class.

4.22.1. IFFReader class

The IFFReader class reads Maya IFF files and calls appropriate methods which have to be implemented in a derived class. A Maya IFF file is composed of chunks that contain the actual data. There can be data chunks that contain the actual data and group chunks that contain the data chunks.

class cgkit.mayaiff.IFFReader(iffType=None)

Creates an instance of the reader. iffType may be a four-character string defining the type of IFF files the object is supposed to handle (it is the type of the first group chunk). If None is passed, any IFF file will be processed. For example, when set to "Maya", the read() method will raise an error if the input file is not a Maya binary file.

filename

The file name (if it could be obtained). This may be used for generating warning or error messages.

read(file)

Read the content of a file. file is either a file like object that can be used to read the content of the file or the name of a file.

abort()

Aborts reading the current file. This method can be called in handler methods to abort reading the file.

onBeginGroup(chunk)

Callback that is called whenever a new group tag begins. chunk is a GroupChunk object containing information about the group chunk.

onEndGroup(chunk)

Callback that is called whenever a group goes out of scope. chunk is a GroupChunk object containing information about the group chunk (it is the same instance that was passed to onBeginGroup()).

onDataChunk(chunk)

Callback that is called for each data chunk. chunk is a Chunk object that contains information about the chunk and that can be used to read the actual chunk data.

4.22.2. Chunk class

A Chunk object is passed to the callback methods of the MBReader class. It contains information about the current chunk and it can be used to read the actual chunk data. A Chunk object has the following attributes and methods:

class cgkit.mayaiff.Chunk
tag

This is a string containing four characters that represent the chunk name.

size

The size in bytes of the data part of the chunk.

pos

The absolute position of the data part within the input file.

depth

The depth of the chunk (i.e. how deep it is nested). The root has a depth of 0.

parent

The GroupChunk object of the parent chunk. In the case of the root group chunk this attribute is None.

chunkPath()

Return a string containing the full path to this chunk. The result is a concatenation of all chunk names that lead to this chunk.

read(bytes=-1)

Read the specified number of bytes from the chunk. If bytes is -1 the entire chunk data is read. The return value is a string containing the binary data.

4.22.3. GroupChunk class

The GroupChunk class is derived from the Chunk class, so it has the same attributes and methods. In addition it defines one more attribute:

class cgkit.mayaiff.GroupChunk
type

This is a string containing four characters that represent the group type.