|
- <!DOCTYPE html>
-
- <html lang="en" data-content_root="../">
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
- <meta property="og:title" content="chunk — Read IFF chunked data" />
- <meta property="og:type" content="website" />
- <meta property="og:url" content="https://docs.python.org/3/library/chunk.html" />
- <meta property="og:site_name" content="Python documentation" />
- <meta property="og:description" content="Source code: Lib/chunk.py This module provides an interface for reading files that use EA IFF 85 chunks. 1 This format is used in at least the Audio Interchange File Format (AIFF/AIFF-C) and the Re..." />
- <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
- <meta property="og:image:alt" content="Python documentation" />
- <meta name="description" content="Source code: Lib/chunk.py This module provides an interface for reading files that use EA IFF 85 chunks. 1 This format is used in at least the Audio Interchange File Format (AIFF/AIFF-C) and the Re..." />
- <meta property="og:image:width" content="200" />
- <meta property="og:image:height" content="200" />
- <meta name="theme-color" content="#3776ab" />
-
- <title>chunk — Read IFF chunked data — Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
-
- <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
- <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
- <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
-
- <script src="../_static/documentation_options.js?v=2c828074"></script>
- <script src="../_static/doctools.js?v=888ff710"></script>
- <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
-
- <script src="../_static/sidebar.js"></script>
-
- <link rel="search" type="application/opensearchdescription+xml"
- title="Search within Python 3.12.3 documentation"
- href="../_static/opensearch.xml"/>
- <link rel="author" title="About these documents" href="../about.html" />
- <link rel="index" title="Index" href="../genindex.html" />
- <link rel="search" title="Search" href="../search.html" />
- <link rel="copyright" title="Copyright" href="../copyright.html" />
- <link rel="next" title="crypt — Function to check Unix passwords" href="crypt.html" />
- <link rel="prev" title="cgitb — Traceback manager for CGI scripts" href="cgitb.html" />
- <link rel="canonical" href="https://docs.python.org/3/library/chunk.html" />
-
-
-
-
-
- <style>
- @media only screen {
- table.full-width-table {
- width: 100%;
- }
- }
- </style>
- <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
- <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
- <script type="text/javascript" src="../_static/copybutton.js"></script>
- <script type="text/javascript" src="../_static/menu.js"></script>
- <script type="text/javascript" src="../_static/search-focus.js"></script>
- <script type="text/javascript" src="../_static/themetoggle.js"></script>
-
- </head>
- <body>
- <div class="mobile-nav">
- <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
- aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
- <nav class="nav-content" role="navigation">
- <label for="menuToggler" class="toggler__label">
- <span></span>
- </label>
- <span class="nav-items-wrapper">
- <a href="https://www.python.org/" class="nav-logo">
- <img src="../_static/py.svg" alt="Python logo"/>
- </a>
- <span class="version_switcher_placeholder"></span>
- <form role="search" class="search" action="../search.html" method="get">
- <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
- <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
- </svg>
- <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
- <input type="submit" value="Go"/>
- </form>
- </span>
- </nav>
- <div class="menu-wrapper">
- <nav class="menu" role="navigation" aria-label="main navigation">
- <div class="language_switcher_placeholder"></div>
-
- <label class="theme-selector-label">
- Theme
- <select class="theme-selector" oninput="activateTheme(this.value)">
- <option value="auto" selected>Auto</option>
- <option value="light">Light</option>
- <option value="dark">Dark</option>
- </select>
- </label>
- <div>
- <h4>Previous topic</h4>
- <p class="topless"><a href="cgitb.html"
- title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code> — Traceback manager for CGI scripts</a></p>
- </div>
- <div>
- <h4>Next topic</h4>
- <p class="topless"><a href="crypt.html"
- title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code> — Function to check Unix passwords</a></p>
- </div>
- <div role="note" aria-label="source link">
- <h3>This Page</h3>
- <ul class="this-page-menu">
- <li><a href="../bugs.html">Report a Bug</a></li>
- <li>
- <a href="https://github.com/python/cpython/blob/main/Doc/library/chunk.rst"
- rel="nofollow">Show Source
- </a>
- </li>
- </ul>
- </div>
- </nav>
- </div>
- </div>
-
-
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="../genindex.html" title="General Index"
- accesskey="I">index</a></li>
- <li class="right" >
- <a href="../py-modindex.html" title="Python Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="crypt.html" title="crypt — Function to check Unix passwords"
- accesskey="N">next</a> |</li>
- <li class="right" >
- <a href="cgitb.html" title="cgitb — Traceback manager for CGI scripts"
- accesskey="P">previous</a> |</li>
-
- <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
- <li><a href="https://www.python.org/">Python</a> »</li>
- <li class="switchers">
- <div class="language_switcher_placeholder"></div>
- <div class="version_switcher_placeholder"></div>
- </li>
- <li>
-
- </li>
- <li id="cpython-language-and-version">
- <a href="../index.html">3.12.3 Documentation</a> »
- </li>
-
- <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
- <li class="nav-item nav-item-2"><a href="superseded.html" accesskey="U">Superseded Modules</a> »</li>
- <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code> — Read IFF chunked data</a></li>
- <li class="right">
-
-
- <div class="inline-search" role="search">
- <form class="inline-search" action="../search.html" method="get">
- <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
- <input type="submit" value="Go" />
- </form>
- </div>
- |
- </li>
- <li class="right">
- <label class="theme-selector-label">
- Theme
- <select class="theme-selector" oninput="activateTheme(this.value)">
- <option value="auto" selected>Auto</option>
- <option value="light">Light</option>
- <option value="dark">Dark</option>
- </select>
- </label> |</li>
-
- </ul>
- </div>
-
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <section id="module-chunk">
- <span id="chunk-read-iff-chunked-data"></span><h1><a class="reference internal" href="#module-chunk" title="chunk: Module to read IFF chunks. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code></a> — Read IFF chunked data<a class="headerlink" href="#module-chunk" title="Link to this heading">¶</a></h1>
- <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/chunk.py">Lib/chunk.py</a></p>
- <div class="deprecated-removed" id="index-0">
- <p><span class="versionmodified">Deprecated since version 3.11, will be removed in version 3.13: </span>The <a class="reference internal" href="#module-chunk" title="chunk: Module to read IFF chunks. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code></a> module is deprecated
- (see <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/#chunk"><strong>PEP 594</strong></a> for details).</p>
- </div>
- <hr class="docutils" />
- <p>This module provides an interface for reading files that use EA IFF 85 chunks.
- <a class="footnote-reference brackets" href="#id2" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> This format is used in at least the Audio Interchange File Format
- (AIFF/AIFF-C) and the Real Media File Format (RMFF). The WAVE audio file format
- is closely related and can also be read using this module.</p>
- <p>A chunk has the following structure:</p>
- <table class="docutils align-default">
- <thead>
- <tr class="row-odd"><th class="head"><p>Offset</p></th>
- <th class="head"><p>Length</p></th>
- <th class="head"><p>Contents</p></th>
- </tr>
- </thead>
- <tbody>
- <tr class="row-even"><td><p>0</p></td>
- <td><p>4</p></td>
- <td><p>Chunk ID</p></td>
- </tr>
- <tr class="row-odd"><td><p>4</p></td>
- <td><p>4</p></td>
- <td><p>Size of chunk in big-endian
- byte order, not including the
- header</p></td>
- </tr>
- <tr class="row-even"><td><p>8</p></td>
- <td><p><em>n</em></p></td>
- <td><p>Data bytes, where <em>n</em> is the
- size given in the preceding
- field</p></td>
- </tr>
- <tr class="row-odd"><td><p>8 + <em>n</em></p></td>
- <td><p>0 or 1</p></td>
- <td><p>Pad byte needed if <em>n</em> is odd
- and chunk alignment is used</p></td>
- </tr>
- </tbody>
- </table>
- <p>The ID is a 4-byte string which identifies the type of chunk.</p>
- <p>The size field (a 32-bit value, encoded using big-endian byte order) gives the
- size of the chunk data, not including the 8-byte header.</p>
- <p>Usually an IFF-type file consists of one or more chunks. The proposed usage of
- the <a class="reference internal" href="#chunk.Chunk" title="chunk.Chunk"><code class="xref py py-class docutils literal notranslate"><span class="pre">Chunk</span></code></a> class defined here is to instantiate an instance at the start
- of each chunk and read from the instance until it reaches the end, after which a
- new instance can be instantiated. At the end of the file, creating a new
- instance will fail with an <a class="reference internal" href="exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EOFError</span></code></a> exception.</p>
- <dl class="py class">
- <dt class="sig sig-object py" id="chunk.Chunk">
- <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">chunk.</span></span><span class="sig-name descname"><span class="pre">Chunk</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">align</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bigendian</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inclheader</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk" title="Link to this definition">¶</a></dt>
- <dd><p>Class which represents a chunk. The <em>file</em> argument is expected to be a
- file-like object. An instance of this class is specifically allowed. The
- only method that is needed is <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code>. If the methods
- <a class="reference internal" href="io.html#io.IOBase.seek" title="io.IOBase.seek"><code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code></a> and <a class="reference internal" href="io.html#io.IOBase.tell" title="io.IOBase.tell"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tell()</span></code></a> are present and don’t
- raise an exception, they are also used.
- If these methods are present and raise an exception, they are expected to not
- have altered the object. If the optional argument <em>align</em> is true, chunks
- are assumed to be aligned on 2-byte boundaries. If <em>align</em> is false, no
- alignment is assumed. The default value is true. If the optional argument
- <em>bigendian</em> is false, the chunk size is assumed to be in little-endian order.
- This is needed for WAVE audio files. The default value is true. If the
- optional argument <em>inclheader</em> is true, the size given in the chunk header
- includes the size of the header. The default value is false.</p>
- <p>A <a class="reference internal" href="#chunk.Chunk" title="chunk.Chunk"><code class="xref py py-class docutils literal notranslate"><span class="pre">Chunk</span></code></a> object supports the following methods:</p>
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.getname">
- <span class="sig-name descname"><span class="pre">getname</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.getname" title="Link to this definition">¶</a></dt>
- <dd><p>Returns the name (ID) of the chunk. This is the first 4 bytes of the
- chunk.</p>
- </dd></dl>
-
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.getsize">
- <span class="sig-name descname"><span class="pre">getsize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.getsize" title="Link to this definition">¶</a></dt>
- <dd><p>Returns the size of the chunk.</p>
- </dd></dl>
-
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.close">
- <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.close" title="Link to this definition">¶</a></dt>
- <dd><p>Close and skip to the end of the chunk. This does not close the
- underlying file.</p>
- </dd></dl>
-
- <p>The remaining methods will raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if called after the
- <a class="reference internal" href="#chunk.Chunk.close" title="chunk.Chunk.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method has been called. Before Python 3.3, they used to
- raise <a class="reference internal" href="exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>, now an alias of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.isatty">
- <span class="sig-name descname"><span class="pre">isatty</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.isatty" title="Link to this definition">¶</a></dt>
- <dd><p>Returns <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
- </dd></dl>
-
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.seek">
- <span class="sig-name descname"><span class="pre">seek</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pos</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">whence</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.seek" title="Link to this definition">¶</a></dt>
- <dd><p>Set the chunk’s current position. The <em>whence</em> argument is optional and
- defaults to <code class="docutils literal notranslate"><span class="pre">0</span></code> (absolute file positioning); other values are <code class="docutils literal notranslate"><span class="pre">1</span></code>
- (seek relative to the current position) and <code class="docutils literal notranslate"><span class="pre">2</span></code> (seek relative to the
- file’s end). There is no return value. If the underlying file does not
- allow seek, only forward seeks are allowed.</p>
- </dd></dl>
-
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.tell">
- <span class="sig-name descname"><span class="pre">tell</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.tell" title="Link to this definition">¶</a></dt>
- <dd><p>Return the current position into the chunk.</p>
- </dd></dl>
-
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.read">
- <span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.read" title="Link to this definition">¶</a></dt>
- <dd><p>Read at most <em>size</em> bytes from the chunk (less if the read hits the end of
- the chunk before obtaining <em>size</em> bytes). If the <em>size</em> argument is
- negative or omitted, read all data until the end of the chunk. An empty
- bytes object is returned when the end of the chunk is encountered
- immediately.</p>
- </dd></dl>
-
- <dl class="py method">
- <dt class="sig sig-object py" id="chunk.Chunk.skip">
- <span class="sig-name descname"><span class="pre">skip</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.skip" title="Link to this definition">¶</a></dt>
- <dd><p>Skip to the end of the chunk. All further calls to <a class="reference internal" href="#chunk.Chunk.read" title="chunk.Chunk.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code></a> for the
- chunk will return <code class="docutils literal notranslate"><span class="pre">b''</span></code>. If you are not interested in the contents of
- the chunk, this method should be called so that the file points to the
- start of the next chunk.</p>
- </dd></dl>
-
- </dd></dl>
-
- <p class="rubric">Footnotes</p>
- <aside class="footnote-list brackets">
- <aside class="footnote brackets" id="id2" role="doc-footnote">
- <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>
- <p>“EA IFF 85” Standard for Interchange Format Files, Jerry Morrison, Electronic
- Arts, January 1985.</p>
- </aside>
- </aside>
- </section>
-
-
- <div class="clearer"></div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <div>
- <h4>Previous topic</h4>
- <p class="topless"><a href="cgitb.html"
- title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code> — Traceback manager for CGI scripts</a></p>
- </div>
- <div>
- <h4>Next topic</h4>
- <p class="topless"><a href="crypt.html"
- title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code> — Function to check Unix passwords</a></p>
- </div>
- <div role="note" aria-label="source link">
- <h3>This Page</h3>
- <ul class="this-page-menu">
- <li><a href="../bugs.html">Report a Bug</a></li>
- <li>
- <a href="https://github.com/python/cpython/blob/main/Doc/library/chunk.rst"
- rel="nofollow">Show Source
- </a>
- </li>
- </ul>
- </div>
- </div>
- <div id="sidebarbutton" title="Collapse sidebar">
- <span>«</span>
- </div>
-
- </div>
- <div class="clearer"></div>
- </div>
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="../genindex.html" title="General Index"
- >index</a></li>
- <li class="right" >
- <a href="../py-modindex.html" title="Python Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="crypt.html" title="crypt — Function to check Unix passwords"
- >next</a> |</li>
- <li class="right" >
- <a href="cgitb.html" title="cgitb — Traceback manager for CGI scripts"
- >previous</a> |</li>
-
- <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
- <li><a href="https://www.python.org/">Python</a> »</li>
- <li class="switchers">
- <div class="language_switcher_placeholder"></div>
- <div class="version_switcher_placeholder"></div>
- </li>
- <li>
-
- </li>
- <li id="cpython-language-and-version">
- <a href="../index.html">3.12.3 Documentation</a> »
- </li>
-
- <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
- <li class="nav-item nav-item-2"><a href="superseded.html" >Superseded Modules</a> »</li>
- <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code> — Read IFF chunked data</a></li>
- <li class="right">
-
-
- <div class="inline-search" role="search">
- <form class="inline-search" action="../search.html" method="get">
- <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
- <input type="submit" value="Go" />
- </form>
- </div>
- |
- </li>
- <li class="right">
- <label class="theme-selector-label">
- Theme
- <select class="theme-selector" oninput="activateTheme(this.value)">
- <option value="auto" selected>Auto</option>
- <option value="light">Light</option>
- <option value="dark">Dark</option>
- </select>
- </label> |</li>
-
- </ul>
- </div>
- <div class="footer">
- ©
- <a href="../copyright.html">
-
- Copyright
-
- </a>
- 2001-2024, Python Software Foundation.
- <br />
- This page is licensed under the Python Software Foundation License Version 2.
- <br />
- Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
- <br />
-
- See <a href="/license.html">History and License</a> for more information.<br />
-
-
- <br />
-
- The Python Software Foundation is a non-profit corporation.
- <a href="https://www.python.org/psf/donations/">Please donate.</a>
- <br />
- <br />
- Last updated on Apr 09, 2024 (13:47 UTC).
-
- <a href="/bugs.html">Found a bug</a>?
-
- <br />
-
- Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
- </div>
-
- </body>
- </html>
|