-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunk.html
More file actions
315 lines (286 loc) · 16.9 KB
/
chunk.html
File metadata and controls
315 lines (286 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!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" lang="zh_TW">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>23.5. chunk — Read IFF chunked data — Python 3.7.0 說明文件</title>
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/translations.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.7.0 說明文件 中搜尋"
href="../_static/opensearch.xml"/>
<link rel="author" title="關於這些文件" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜尋" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="23.6. colorsys — Conversions between color systems" href="colorsys.html" />
<link rel="prev" title="23.4. wave — Read and write WAV files" href="wave.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/library/chunk.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="colorsys.html" title="23.6. colorsys — Conversions between color systems"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="wave.html" title="23.4. wave — Read and write WAV files"
accesskey="P">上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 標準函式庫 (Standard Library)</a> »</li>
<li class="nav-item nav-item-2"><a href="mm.html" accesskey="U">23. Multimedia Services</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-chunk">
<span id="chunk-read-iff-chunked-data"></span><h1>23.5. <a class="reference internal" href="#module-chunk" title="chunk: Module to read IFF chunks."><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="本標題的永久連結">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/chunk.py">Lib/chunk.py</a></p>
<hr class="docutils" id="index-0" />
<p>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 class="row-odd"><th class="head">Offset</th>
<th class="head">Length</th>
<th class="head">Contents</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>0</td>
<td>4</td>
<td>Chunk ID</td>
</tr>
<tr class="row-odd"><td>4</td>
<td>4</td>
<td>Size of chunk in big-endian
byte order, not including the
header</td>
</tr>
<tr class="row-even"><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 class="row-odd"><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 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="class">
<dt id="chunk.Chunk">
<em class="property">class </em><code class="descclassname">chunk.</code><code class="descname">Chunk</code><span class="sig-paren">(</span><em>file</em>, <em>align=True</em>, <em>bigendian=True</em>, <em>inclheader=False</em><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk" title="本定義的永久連結">¶</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="method">
<dt id="chunk.Chunk.getname">
<code class="descname">getname</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.getname" title="本定義的永久連結">¶</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="method">
<dt id="chunk.Chunk.getsize">
<code class="descname">getsize</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.getsize" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the size of the chunk.</p>
</dd></dl>
<dl class="method">
<dt id="chunk.Chunk.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.close" title="本定義的永久連結">¶</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="method">
<dt id="chunk.Chunk.isatty">
<code class="descname">isatty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.isatty" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="chunk.Chunk.seek">
<code class="descname">seek</code><span class="sig-paren">(</span><em>pos</em>, <em>whence=0</em><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.seek" title="本定義的永久連結">¶</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="method">
<dt id="chunk.Chunk.tell">
<code class="descname">tell</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.tell" title="本定義的永久連結">¶</a></dt>
<dd><p>Return the current position into the chunk.</p>
</dd></dl>
<dl class="method">
<dt id="chunk.Chunk.read">
<code class="descname">read</code><span class="sig-paren">(</span><em>size=-1</em><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.read" title="本定義的永久連結">¶</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="method">
<dt id="chunk.Chunk.skip">
<code class="descname">skip</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#chunk.Chunk.skip" title="本定義的永久連結">¶</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">註解</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>「EA IFF 85」 Standard for Interchange Format Files, Jerry Morrison, Electronic
Arts, January 1985.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>上個主題</h4>
<p class="topless"><a href="wave.html"
title="上一章">23.4. <code class="docutils literal notranslate"><span class="pre">wave</span></code> — Read and write WAV files</a></p>
<h4>下個主題</h4>
<p class="topless"><a href="colorsys.html"
title="下一章">23.6. <code class="docutils literal notranslate"><span class="pre">colorsys</span></code> — Conversions between color systems</a></p>
<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/3.7/Doc/library/chunk.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="colorsys.html" title="23.6. colorsys — Conversions between color systems"
>下一頁</a> |</li>
<li class="right" >
<a href="wave.html" title="23.4. wave — Read and write WAV files"
>上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 標準函式庫 (Standard Library)</a> »</li>
<li class="nav-item nav-item-2"><a href="mm.html" >23. Multimedia Services</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 2001-2018, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on 8月 22, 2018.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.7.
</div>
</body>
</html>