Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60b66e1

Browse files
committed
Update to Sjoerd's documentation of the chunk module, with some
additions from Moshe's version. Used my table for describing the chunk format, and added some markup and index entries.
1 parent 16e0bab commit 60b66e1

1 file changed

Lines changed: 64 additions & 32 deletions

File tree

Doc/lib/libchunk.tex

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,98 @@
11
\section{\module{chunk} ---
2-
Helper for reading IFF chunks}
2+
Read IFF chunked data}
33

44
\declaremodule{standard}{chunk}
5-
\sectionauthor{Moshe Zadka}{[email protected]}
6-
\modulesynopsis{Helper class for reading from IFF-based file formats.}
5+
\modulesynopsis{Module to read IFF chunks.}
6+
\moduleauthor{Sjoerd Mullender}{[email protected]}
7+
\sectionauthor{Sjoerd Mullender}{[email protected]}
78

8-
The \module{chunk} module defines a class for interfacing to ``IFF''
9-
chunk-based files, like TIFF or AIFF. This is used as a helper module
10-
for the \refmodule{aifc} and \refmodule{wave} modules.
119

12-
The \module{chunk} module defines the following class:
1310

14-
\begin{classdesc}{Chunk}{file\optional{, align}}
15-
The chunk from \var{file} starting at \var{file}'s current
16-
position. The \var{align} argument, which defaults to true, determines
17-
whether to align chunk data on 2-byte boundaries.
18-
19-
\exception{EOFError} is raised if \var{file} does not contain enough
20-
data to read the IFF header.
21-
\end{classdesc}
11+
This module provides an interface for reading files that use EA IFF 85
12+
chunks.\footnote{``EA IFF 85'' Standard for Interchange Format Files,
13+
Jerry Morrison, Electronic Arts, January 1985.} This format is used
14+
in at least the Audio\index{Audio Interchange File
15+
Format}\index{AIFF}\index{AIFF-C} Interchange File Format
16+
(AIFF/AIFF-C), the Real\index{Real Media File Format} Media File
17+
Format\index{RMFF} (RMFF), and the
18+
Tagged\index{Tagged Image File Format} Image File Format\index{TIFF}
19+
(TIFF).
2220

23-
The IFF header format is described in this table:
21+
A chunk has the following structure:
2422

2523
\begin{tableiii}{c|c|l}{textrm}{Offset}{Length}{Contents}
2624
\lineiii{0}{4}{Chunk ID}
2725
\lineiii{4}{4}{Size of chunk in big-endian byte order, including the
2826
header}
27+
\lineiii{8}{\var{n}}{Data bytes, where \var{n} is the size given in
28+
the preceeding field}
29+
\lineiii{8 + \var{n}}{0 or 1}{Pad byte needed if \var{n} is odd and
30+
chunk alignment is used}
2931
\end{tableiii}
3032

33+
The ID is a 4-byte string which identifies the type of chunk.
34+
35+
The size field (a 32-bit value, encoded using big-endian byte order)
36+
gives the size of the whole chunk, including the 8-byte header.
3137

32-
\subsection{Chunk Objects \label{iff-chunk-objects}}
38+
Usually an IFF-type file consists of one or more chunks. The proposed
39+
usage of the \class{Chunk} class defined here is to instantiate an
40+
instance at the start of each chunk and read from the instance until
41+
it reaches the end, after which a new instance can be instantiated.
42+
At the end of the file, creating a new instance will fail with a
43+
\exception{EOFError} exception.
3344

34-
Chunk objects have the following methods:
45+
\begin{classdesc}{Chunk}{file\optional{, align}}
46+
Class which represents a chunk. The \var{file} argument is expected
47+
to be a file-like object. An instance of this class is specifically
48+
allowed. The only method that is needed is \method{read()}. If the
49+
methods \method{seek()} and \method{tell()} are present and don't
50+
raise an exception, they are also used. If these methods are present
51+
and raise an exception, they are expected to not have altered the
52+
object. If the optional argument \var{align} is true, chunks are
53+
assumed to be aligned on 2-byte boundaries. If \var{align} is
54+
false, no alignment is assumed. The default value is true.
55+
\end{classdesc}
56+
57+
A \class{Chunk} object supports the following methods:
3558

3659
\begin{methoddesc}{getname}{}
37-
Return the ID of the chunk.
60+
Returns the name (ID) of the chunk. This is the first 4 bytes of the
61+
chunk.
3862
\end{methoddesc}
3963

4064
\begin{methoddesc}{close}{}
41-
Close the chunk, forwarding the file pointer to the end of the chunk.
65+
Close and skip to the end of the chunk. This does not close the
66+
underlying file.
4267
\end{methoddesc}
4368

69+
The remaining methods will raise \exception{IOError} if called after
70+
the \method{close()} method has been called.
71+
4472
\begin{methoddesc}{isatty}{}
45-
Returns false unless the chunk has been closed, in which case
46-
\exception{ValueError} is raised.
73+
Returns \code{0}.
4774
\end{methoddesc}
4875

49-
\begin{methoddesc}{seek}{offset\optional{, whence}}
50-
Seek to a position within the chunk. If file pointer is not seekable,
51-
or \var{offset} would point outside the chunk, an error is raised.
52-
\var{whence} is interpreted the same as for the \method{seek()} method
53-
on file objects; see section \ref{bltin-file-objects} for more
54-
information.
76+
\begin{methoddesc}{seek}{pos\optional{, whence}}
77+
Set the chunk's current position. The \var{whence} argument is
78+
optional and defaults to \code{0} (absolute file positioning); other
79+
values are \code{1} (seek relative to the current position) and
80+
\code{2} (seek relative to the file's end). There is no return value.
81+
If the underlying file does not allow seek, only forward seeks are
82+
allowed.
5583
\end{methoddesc}
5684

5785
\begin{methoddesc}{tell}{}
58-
Return the current position within this chunk.
86+
Return the current position into the chunk.
5987
\end{methoddesc}
6088

61-
\begin{methoddesc}{read}{\optional{n}}
62-
Read at most \var{n} bytes from the chunk. If \var{n} is omitted
63-
or negative, read until the end of the chunk.
89+
\begin{methoddesc}{read}{\optional{size}}
90+
Read at most \var{size} bytes from the chunk (less if the read hits
91+
the end of the chunk before obtaining \var{size} bytes). If the
92+
\var{size} argument is negative or omitted, read all data until the
93+
end of the chunk. The bytes are returned as a string object. An
94+
empty string is returned when the end of the chunk is encountered
95+
immediately.
6496
\end{methoddesc}
6597

6698
\begin{methoddesc}{skip}{}

0 commit comments

Comments
 (0)