Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8f1462e52e1797a02c97073eed0b7f92 > files > 676

python-docs-2.6.5-2.5mdv2010.2.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>22.6. chunk — Read IFF chunked data &mdash; Python v2.6.5 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.5',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.5 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.5 documentation" href="../index.html" />
    <link rel="up" title="22. Multimedia Services" href="mm.html" />
    <link rel="next" title="22.7. colorsys — Conversions between color systems" href="colorsys.html" />
    <link rel="prev" title="22.5. wave — Read and write WAV files" href="wave.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <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="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="colorsys.html" title="22.7. colorsys — Conversions between color systems"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="wave.html" title="22.5. wave — Read and write WAV files"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.5 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="mm.html" accesskey="U">22. Multimedia Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-chunk">
<h1>22.6. <tt class="xref docutils literal"><span class="pre">chunk</span></tt> &#8212; Read IFF chunked data<a class="headerlink" href="#module-chunk" title="Permalink to this headline">¶</a></h1>
<p id="index-235">This module provides an interface for reading files that use EA IFF 85 chunks.
<a class="footnote-reference" href="#id2" id="id1">[1]</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 border="1" class="docutils">
<colgroup>
<col width="19%" />
<col width="17%" />
<col width="65%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Offset</th>
<th class="head">Length</th>
<th class="head">Contents</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>0</td>
<td>4</td>
<td>Chunk ID</td>
</tr>
<tr><td>4</td>
<td>4</td>
<td>Size of chunk in big-endian
byte order, not including the
header</td>
</tr>
<tr><td>8</td>
<td><em>n</em></td>
<td>Data bytes, where <em>n</em> is the
size given in the preceding
field</td>
</tr>
<tr><td>8 + <em>n</em></td>
<td>0 or 1</td>
<td>Pad byte needed if <em>n</em> is odd
and chunk alignment is used</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 title="chunk.Chunk" class="reference internal" href="#chunk.Chunk"><tt class="xref docutils literal"><span class="pre">Chunk</span></tt></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 a <a title="exceptions.EOFError" class="reference external" href="exceptions.html#exceptions.EOFError"><tt class="xref docutils literal"><span class="pre">EOFError</span></tt></a> exception.</p>
<dl class="class">
<dt id="chunk.Chunk">
<em class="property">class </em><tt class="descclassname">chunk.</tt><tt class="descname">Chunk</tt><big>(</big><em>file</em><span class="optional">[</span>, <em>align</em>, <em>bigendian</em>, <em>inclheader</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#chunk.Chunk" title="Permalink 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 <a title="chunk.Chunk.read" class="reference internal" href="#chunk.Chunk.read"><tt class="xref docutils literal"><span class="pre">read()</span></tt></a>.  If the methods <a title="chunk.Chunk.seek" class="reference internal" href="#chunk.Chunk.seek"><tt class="xref docutils literal"><span class="pre">seek()</span></tt></a> and
<a title="chunk.Chunk.tell" class="reference internal" href="#chunk.Chunk.tell"><tt class="xref docutils literal"><span class="pre">tell()</span></tt></a> are present and don&#8217;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 title="chunk.Chunk" class="reference internal" href="#chunk.Chunk"><tt class="xref docutils literal"><span class="pre">Chunk</span></tt></a> object supports the following methods:</p>
<dl class="method">
<dt id="chunk.Chunk.getname">
<tt class="descname">getname</tt><big>(</big><big>)</big><a class="headerlink" href="#chunk.Chunk.getname" title="Permalink to this definition">¶</a></dt>
<dd>Returns the name (ID) of the chunk.  This is the first 4 bytes of the
chunk.</dd></dl>

<dl class="method">
<dt id="chunk.Chunk.getsize">
<tt class="descname">getsize</tt><big>(</big><big>)</big><a class="headerlink" href="#chunk.Chunk.getsize" title="Permalink to this definition">¶</a></dt>
<dd>Returns the size of the chunk.</dd></dl>

<dl class="method">
<dt id="chunk.Chunk.close">
<tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#chunk.Chunk.close" title="Permalink to this definition">¶</a></dt>
<dd>Close and skip to the end of the chunk.  This does not close the
underlying file.</dd></dl>

<p>The remaining methods will raise <a title="exceptions.IOError" class="reference external" href="exceptions.html#exceptions.IOError"><tt class="xref docutils literal"><span class="pre">IOError</span></tt></a> if called after the
<a title="chunk.Chunk.close" class="reference internal" href="#chunk.Chunk.close"><tt class="xref docutils literal"><span class="pre">close()</span></tt></a> method has been called.</p>
<dl class="method">
<dt id="chunk.Chunk.isatty">
<tt class="descname">isatty</tt><big>(</big><big>)</big><a class="headerlink" href="#chunk.Chunk.isatty" title="Permalink to this definition">¶</a></dt>
<dd>Returns <tt class="xref docutils literal"><span class="pre">False</span></tt>.</dd></dl>

<dl class="method">
<dt id="chunk.Chunk.seek">
<tt class="descname">seek</tt><big>(</big><em>pos</em><span class="optional">[</span>, <em>whence</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#chunk.Chunk.seek" title="Permalink to this definition">¶</a></dt>
<dd>Set the chunk&#8217;s current position.  The <em>whence</em> argument is optional and
defaults to <tt class="docutils literal"><span class="pre">0</span></tt> (absolute file positioning); other values are <tt class="docutils literal"><span class="pre">1</span></tt>
(seek relative to the current position) and <tt class="docutils literal"><span class="pre">2</span></tt> (seek relative to the
file&#8217;s end).  There is no return value. If the underlying file does not
allow seek, only forward seeks are allowed.</dd></dl>

<dl class="method">
<dt id="chunk.Chunk.tell">
<tt class="descname">tell</tt><big>(</big><big>)</big><a class="headerlink" href="#chunk.Chunk.tell" title="Permalink to this definition">¶</a></dt>
<dd>Return the current position into the chunk.</dd></dl>

<dl class="method">
<dt id="chunk.Chunk.read">
<tt class="descname">read</tt><big>(</big><span class="optional">[</span><em>size</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#chunk.Chunk.read" title="Permalink to this definition">¶</a></dt>
<dd>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.  The bytes
are returned as a string object.  An empty string is returned when the end
of the chunk is encountered immediately.</dd></dl>

<dl class="method">
<dt id="chunk.Chunk.skip">
<tt class="descname">skip</tt><big>(</big><big>)</big><a class="headerlink" href="#chunk.Chunk.skip" title="Permalink to this definition">¶</a></dt>
<dd>Skip to the end of the chunk.  All further calls to <a title="chunk.Chunk.read" class="reference internal" href="#chunk.Chunk.read"><tt class="xref docutils literal"><span class="pre">read()</span></tt></a> for the
chunk will return <tt class="docutils literal"><span class="pre">''</span></tt>.  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.</dd></dl>

</dd></dl>

<p class="rubric">Footnotes</p>
<table class="docutils footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>&#8220;EA IFF 85&#8221; Standard for Interchange Format Files, Jerry Morrison, Electronic
Arts, January 1985.</td></tr>
</tbody>
</table>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="wave.html"
                                  title="previous chapter">22.5. <tt class="docutils literal"><span class="pre">wave</span></tt> &#8212; Read and write WAV files</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="colorsys.html"
                                  title="next chapter">22.7. <tt class="docutils literal"><span class="pre">colorsys</span></tt> &#8212; Conversions between color systems</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/chunk.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <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="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="colorsys.html" title="22.7. colorsys — Conversions between color systems"
             >next</a> |</li>
        <li class="right" >
          <a href="wave.html" title="22.5. wave — Read and write WAV files"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.5 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="mm.html" >22. Multimedia Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2010, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Mar 19, 2010.
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.5.
    </div>

  </body>
</html>