avifilelib.riff module

exception avifilelib.riff.ChunkFormatException

Bases: Exception

Raised when the underlying chunk data does not match the expected format.

exception avifilelib.riff.ChunkTypeException

Bases: Exception

Raised when the underlying chunk data does not match the expected RIFF type.

class avifilelib.riff.RIFFChunk(file, align=False, bigendian=False, inclheader=False)

Bases: chunk.Chunk

A class for reading RIFF chunks.

A customized version of the chunk.Chunk class to be used for reading RIFF files. The main customization being that the bigendian parameter defaults to False rather than True. Additionally, the object will correctly handle RIFF ‘LIST’ chunks.

Parameters:
  • file (file_like) – A file-like object (has read(), seek(), and tell() methods.
  • align (bool) – Indicates whether the chunk should aligned to a 2-byte boundary.
  • bigendian (bool) – Indicates whether the byte order of the data should be big endian or little endian.
  • inclheader (bool) – Specifies whether the chunk size that will be read includes the size of the chunk header (name and size).
getlisttype()

Type of RIFF list.

Returns:The four character type identifier of the RIFF list or None if the chunk is not a RIFF list.
Return type:str
islist()

Indicates if the chunk contains a RIFF list.

Returns:True if the chunk contains a RIFF list.
Return type:bool
avifilelib.riff.rollback(file_like, reraise=False)

Context manager to recover from failed chunk creation.

This context manager can be used to wrap calls to methods that attempt to read a RIFF chunk but require the chunk to be of a specific type. If the method raises a ChunkTypeException, this context manager catches the ChunkTypeException and rewinds the file_like object to its position before the failed call.

Parameters:
  • file_like (file-like) – A file-like object (having at least tell() and seek() methods).
  • reraise (bool) – If True, any ChunkTypeException raised while within the context manager will be reraised after file_like is rewound.
Yields:

file-like – the object file_like passed as a parameter.