1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
5 <refentry id="class-giobufferedinputstream">
7 <refname>gio.BufferedInputStream</refname>
8 <refpurpose>Buffered Input Stream</refpurpose>
12 <title>Synopsis</title>
14 <classsynopsis language="python">
15 <ooclass><classname>gio.BufferedInputStream</classname></ooclass>
16 <ooclass><classname><link linkend="class-giofilterinputstream">gio.FilterInputStream</link></classname></ooclass>
18 <constructorsynopsis language="python">
19 <methodname><link linkend="constructor-giobufferedinputstream">gio.BufferedInputStream</link></methodname>
20 <methodparam><parameter role="keyword">base_stream</parameter></methodparam>
21 </constructorsynopsis>
23 <methodsynopsis language="python">
24 <methodname><link linkend="method-giobufferedinputstream--fill">fill</link></methodname>
25 <methodparam><parameter role="keyword">count</parameter></methodparam>
26 <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
28 <methodsynopsis language="python">
29 <methodname><link linkend="method-giobufferedinputstream--fill-async">fill_async</link></methodname>
30 <methodparam><parameter role="keyword">count</parameter></methodparam>
31 <methodparam><parameter role="keyword">callback</parameter></methodparam>
32 <methodparam><parameter role="keyword">io_priority</parameter><initializer>glib.PRIORITY_DEFAULT</initializer></methodparam>
33 <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
34 <methodparam><parameter role="keyword">user_data</parameter><initializer>None</initializer></methodparam>
36 <methodsynopsis language="python">
37 <methodname><link linkend="method-giobufferedinputstream--fill-finish">fill_finish</link></methodname>
38 <methodparam><parameter role="keyword">result</parameter></methodparam>
40 <methodsynopsis language="python">
41 <methodname><link linkend="method-giobufferedinputstream--get-available">get_available</link></methodname>
42 <methodparam></methodparam>
44 <methodsynopsis language="python">
45 <methodname><link linkend="method-giobufferedinputstream--get-buffer-size">get_buffer_size</link></methodname>
46 <methodparam></methodparam>
48 <methodsynopsis language="python">
49 <methodname><link linkend="method-giobufferedinputstream--read-byte">read_byte</link></methodname>
50 <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
52 <methodsynopsis language="python">
53 <methodname><link linkend="method-giobufferedinputstream--set-buffer-size">set_buffer_size</link></methodname>
54 <methodparam><parameter role="keyword">size</parameter></methodparam>
60 <emphasis role="bold">Functions</emphasis>
62 <methodsynopsis language="python">
63 <methodname><link linkend="function-gio--buffered-input-stream-new-sized">gio.buffered_input_stream_new_sized</link></methodname>
64 <methodparam><parameter role="keyword">size</parameter></methodparam>
65 </methodsynopsis></programlisting>
70 <title>Ancestry</title>
72 <synopsis>+-- <link linkend="class-gobject">gobject.GObject</link>
73 +-- <link linkend="class-gioinputstream">gio.InputStream</link>
74 +-- <link linkend="class-giofilterinputstream">gio.FilterInputStream</link>
75 +-- <link linkend="class-giobufferedinputstream">gio.BufferedInputStream</link>
80 <refsect1 id="properties-giobufferedinputstream">
81 <title>gio.BufferedInputStream Properties</title>
83 <blockquote role="properties">
84 <informaltable pgwide="1" frame="none">
86 <colspec column="1" colwidth="1in"/>
87 <colspec column="2" colwidth="1in"/>
88 <colspec column="3" colwidth="4in"/>
91 <entry>"buffer-size"</entry>
92 <entry>Read - Write - Construct</entry>
93 <entry>The size of the backend buffer. Allowed values: >= 1. Default value: 4096.</entry>
103 <title>Description</title>
106 <link linkend="class-giobufferedinputstream"><classname>gio.BufferedInputStream</classname></link>
107 implements <link linkend="class-giofilterinputstream"><classname>gio.FilterInputStream</classname></link>
108 and provides for buffered reads.
112 <link linkend="class-giobufferedinputstream"><classname>gio.BufferedInputStream</classname></link>'s
113 buffer size is set at 4 kilobytes.
116 To create a buffered input stream, use
117 <methodname><link linkend="constructor-giobufferedinputstream">gio.BufferedInputStream</link></methodname>(),
118 or <methodname><link linkend="function-gio--buffered-input-stream-new-sized">gio.buffered_input_stream_new_sized</link></methodname>()
119 to specify the buffer's size at construction.
122 To get the size of a buffer within a buffered input stream, use
123 <methodname><link linkend="method-giobufferedinputstream--get-buffer-size">get_buffer_size</link></methodname>().
124 To change the size of a buffered input stream's buffer, use
125 <methodname><link linkend="method-giobufferedinputstream--set-buffer-size">set_buffer_size</link></methodname>().
126 Note that the buffer's size cannot be reduced below the size of the data within the buffer.
130 <refsect1 id="constructor-giobufferedinputstream">
131 <title>Constructor</title>
133 <programlisting><constructorsynopsis language="python">
134 <methodname>gio.BufferedInputStream</methodname>
135 <methodparam><parameter role="keyword">base_stream</parameter></methodparam>
136 </constructorsynopsis></programlisting>
139 <term><parameter>base_stream</parameter> :</term>
141 <link linkend="class-gioinputstream"><classname>gio.InputStream</classname></link>.
142 </simpara></listitem>
145 <term><emphasis>Returns</emphasis> :</term>
146 <listitem><simpara>a new
147 <link linkend="class-gioinputstream"><classname>gio.InputStream</classname></link>
148 for the given base_stream.
149 </simpara></listitem>
154 Creates a new <link linkend="class-gioinputstream"><classname>gio.InputStream</classname></link>
155 from the given base_stream, with a buffer set to the default size (4 kilobytes).
161 <title>Methods</title>
163 <refsect2 id="method-giobufferedinputstream--fill">
164 <title>gio.BufferedInputStream.fill</title>
166 <programlisting><methodsynopsis language="python">
167 <methodname>fill</methodname>
168 <methodparam><parameter role="keyword">count</parameter></methodparam>
169 <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
170 </methodsynopsis></programlisting>
174 <term><parameter role="keyword">count</parameter> :</term>
175 <listitem><simpara>the number of bytes that will be read from the stream.
176 </simpara></listitem>
179 <term><parameter role="keyword">cancellable</parameter> :</term>
180 <listitem><simpara>optional
181 <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
182 object, <literal>None</literal> to ignore.
183 </simpara></listitem>
186 <term><emphasis>Returns</emphasis> :</term>
187 <listitem><simpara>the number of bytes read into stream's buffer,
188 up to count, or -1 on error.
189 </simpara></listitem>
194 The <methodname>fill</methodname>() method tries to read count bytes
195 from the stream into the buffer. Will block during this read.
198 If count is zero, returns zero and does nothing. A value of count
199 larger than G_MAXSSIZE will cause a gio.ERROR_INVALID_ARGUMENT error.
202 On success, the number of bytes read into the buffer is returned. It
203 is not an error if this is not the same as the requested size, as it can
204 happen e.g. near the end of a file. Zero is returned on end of file
205 (or if count is zero), but never otherwise.
208 If count is -1 then the attempted read size is equal to the number
209 of bytes that are required to fill the buffer.
212 If cancellable is not <literal>None</literal>, then the operation can
213 be cancelled by triggering the cancellable object from another thread.
214 If the operation was cancelled, the error gio.ERROR_CANCELLED will be
215 returned. If an operation was partially finished when the operation was
216 cancelled the partial result will be returned, without an error.
219 On error -1 is returned and error is set accordingly.
222 For the asynchronous, non-blocking, version of this function, see
223 <methodname><link linkend="method-giobufferedinputstream--fill-async">gio.BufferedInputStream.fill_async</link></methodname>().
227 <refsect2 id="method-giobufferedinputstream--fill-async">
228 <title>gio.BufferedInputStream.fill_async</title>
230 <programlisting><methodsynopsis language="python">
231 <methodname>fill_async</methodname>
232 <methodparam><parameter role="keyword">count</parameter></methodparam>
233 <methodparam><parameter role="keyword">callback</parameter></methodparam>
234 <methodparam><parameter role="keyword">io_priority</parameter><initializer>glib.PRIORITY_DEFAULT</initializer></methodparam>
235 <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
236 <methodparam><parameter role="keyword">user_data</parameter><initializer>None</initializer></methodparam>
237 </methodsynopsis></programlisting>
241 <term><parameter role="keyword">count</parameter> :</term>
242 <listitem><simpara>the number of bytes that will be read from the stream.
243 </simpara></listitem>
246 <term><parameter>callback</parameter> :</term>
247 <listitem><simpara>a GAsyncReadyCallback to call when the request is satisfied.
248 </simpara></listitem>
251 <term><parameter>io_priority</parameter> :</term>
252 <listitem><simpara>the
253 <xref linkend="glib-priority-constants" endterm="glib-priority-constants-title"></xref>
255 </simpara></listitem>
258 <term><parameter>cancellable</parameter> :</term>
259 <listitem><simpara>optional
260 <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
261 object, <literal>None</literal> to ignore.</simpara></listitem>
264 <term><parameter>user_data</parameter> :</term>
265 <listitem><simpara>the data to pass to callback function.
266 </simpara></listitem>
271 The <methodname>fill_async</methodname>() method reads data into stream's
272 buffer asynchronously, up to count size. io_priority can be used to
276 For the synchronous version of this function, see
277 <methodname><link linkend="method-giobufferedinputstream--fill">gio.BufferedInputStream.fill</link></methodname>().
280 If cancellable is not <literal>None</literal>, then the operation can be cancelled
281 by triggering the cancellable object from another thread. If the operation was
282 cancelled, the error gio.ERROR_CANCELLED will be set
285 If count is -1 then the attempted read size is equal to the number of bytes
286 that are required to fill the buffer.
290 <refsect2 id="method-giobufferedinputstream--fill-finish">
291 <title>gio.BufferedInputStream.fill_finish</title>
293 <programlisting><methodsynopsis language="python">
294 <methodname>fill_finish</methodname>
295 <methodparam><parameter role="keyword">result</parameter></methodparam>
296 </methodsynopsis></programlisting>
300 <term><parameter role="keyword">result</parameter> :</term>
301 <listitem><simpara>a <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>.
302 </simpara></listitem>
305 <term><emphasis>Returns</emphasis> :</term>
306 <listitem><simpara>the size of the read stream, or -1 on an error.
307 </simpara></listitem>
312 The <methodname>fill_finish</methodname>() method finishes an asynchronous
313 file append operation started with
314 <methodname><link linkend="method-giobufferedinputstream--fill-async">gio.BufferedInputStream.fill_async</link></methodname>().
318 <refsect2 id="method-giobufferedinputstream--get-available">
319 <title>gio.BufferedInputStream.get_available</title>
321 <programlisting><methodsynopsis language="python">
322 <methodname>get_available</methodname>
323 <methodparam></methodparam>
324 </methodsynopsis></programlisting>
328 <term><emphasis>Returns</emphasis> :</term>
329 <listitem><simpara>size of the available stream.
330 </simpara></listitem>
335 The <methodname>get_available</methodname>() method gets the size of
336 the available data within the stream.
340 <refsect2 id="method-giobufferedinputstream--get-buffer-size">
341 <title>gio.BufferedInputStream.get_buffer_size</title>
343 <programlisting><methodsynopsis language="python">
344 <methodname>get_buffer_size</methodname>
345 <methodparam></methodparam>
346 </methodsynopsis></programlisting>
350 <term><emphasis>Returns</emphasis> :</term>
351 <listitem><simpara>the current buffer size.
352 </simpara></listitem>
357 The <methodname>get_buffer_size</methodname>() method gets the size
362 <refsect2 id="method-giobufferedinputstream--read-byte">
363 <title>gio.BufferedInputStream.read_byte</title>
365 <programlisting><methodsynopsis language="python">
366 <methodname>read_byte</methodname>
367 <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
368 </methodsynopsis></programlisting>
372 <term><parameter role="keyword">cancellable</parameter> :</term>
373 <listitem><simpara>optional
374 <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
375 object, <literal>None</literal> to ignore.
376 </simpara></listitem>
379 <term><emphasis>Returns</emphasis> :</term>
380 <listitem><simpara>the byte read from the stream, or -1 on end of stream or error.
381 </simpara></listitem>
386 The <methodname>read_byte</methodname>() method tries to read a single
387 byte from the stream or the buffer. Will block during this read.
390 On success, the byte read from the stream is returned. On end of stream -1
391 is returned but it's not an exceptional error and error is not set.
394 If cancellable is not <literal>None</literal>, then the operation can
395 be cancelled by triggering the cancellable object from another thread.
396 If the operation was cancelled, the error gio.ERROR_CANCELLED will be
397 returned. If an operation was partially finished when the operation was
398 cancelled the partial result will be returned, without an error.
401 On error -1 is returned and error is set accordingly.
405 <refsect2 id="method-giobufferedinputstream--set-buffer-size">
406 <title>gio.BufferedInputStream.set_buffer_size</title>
408 <programlisting><methodsynopsis language="python">
409 <methodname>set_buffer_size</methodname>
410 <methodparam><parameter role="keyword">size</parameter></methodparam>
411 </methodsynopsis></programlisting>
415 <term><parameter role="keyword">size</parameter> :</term>
416 <listitem><simpara>the new buffer size.
417 </simpara></listitem>
422 The <methodname>set_buffer_size</methodname>() method sets the size
423 of the internal buffer of stream to size, or to the size of the contents
424 of the buffer. The buffer can never be resized smaller than its current contents.
430 <title>Functions</title>
432 <refsect2 id="function-gio--buffered-input-stream-new-sized">
433 <title>gio.buffered_input_stream_new_sized</title>
435 <programlisting><methodsynopsis language="python">
436 <methodname>buffered_input_stream_new_sized</methodname>
437 <methodparam><parameter role="keyword">size</parameter></methodparam>
438 </methodsynopsis></programlisting>
442 <term><parameter>size</parameter> :</term>
443 <listitem><simpara>the requested buffer size.
444 </simpara></listitem>
447 <term><emphasis>Returns</emphasis> :</term>
448 <listitem><simpara>A new
449 <link linkend="class-gioinputstream"><classname>gio.InputStream</classname></link>.
450 </simpara></listitem>
455 The <methodname>buffered_input_stream_new_sized</methodname>() function creates
456 a new <link linkend="class-giobufferedinputstream"><classname>gio.BufferedInputStream</classname></link>
457 from the given base_stream, with a buffer set to size.