all Python 3until 3.13Removed from the standard libraryterm
chunk
removed modules
Read IFF chunks: a 4-byte ID, a length, then data. Removed in Python 3.13 — read the chunk header with struct.
Syntax
import chunk # до 3.13
chunk.Chunk(file) read one chunk of the IFF format that AIFF, RIFF and WAV are made of: getname() returned the ID, getsize() the length, read() the data, skip() jumped to the next chunk. PEP 594 dropped it: only aifc and wave used it, and wave got its own code. How to port: read the 8-byte header and parse it with struct.unpack('>4sI', ...) — the length is big-endian for IFF and AIFF, use '<4sI' for RIFF and WAV; then file.read(size) takes the data. The standard-chunk package on PyPI restores the module.
Examples
# Python 3.13+
try:
import chunk
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.13+
import io, struct
f = io.BytesIO(b'NAME\x00\x00\x00\x03abc')
name, size = struct.unpack('>4sI', f.read(8))
print(name, size, f.read(size)) # → b'NAME' 3 b'abc'
import chunk, io
c = chunk.Chunk(io.BytesIO(b'NAME\x00\x00\x00\x03abc'))
print(c.getname(), c.getsize(), c.read()) # → b'NAME' 3 b'abc'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy