Gio.BufferedInputStream

g GObject.GInterface GObject.GInterface Gio.Seekable Gio.Seekable GObject.GInterface->Gio.Seekable GObject.Object GObject.Object Gio.InputStream Gio.InputStream GObject.Object->Gio.InputStream Gio.BufferedInputStream Gio.BufferedInputStream Gio.FilterInputStream Gio.FilterInputStream Gio.FilterInputStream->Gio.BufferedInputStream Gio.InputStream->Gio.FilterInputStream Gio.Seekable->Gio.BufferedInputStream

Subclasses:

Gio.DataInputStream

Methods

Inherited:

Gio.FilterInputStream (3), Gio.InputStream (19), GObject.Object (37), Gio.Seekable (5)

Structs:

GObject.ObjectClass (5)

class

new (base_stream)

class

new_sized (base_stream, size)

fill (count, cancellable)

fill_async (count, io_priority, cancellable, callback, *user_data)

fill_finish (result)

get_available ()

get_buffer_size ()

peek (buffer, offset)

peek_buffer ()

read_byte (cancellable)

set_buffer_size (size)

Virtual Methods

Inherited:

Gio.InputStream (9), GObject.Object (7), Gio.Seekable (5)

do_fill (count, cancellable)

do_fill_async (count, io_priority, cancellable, callback, *user_data)

do_fill_finish (result)

Properties

Inherited:

Gio.FilterInputStream (2)

Name

Type

Flags

Short Description

buffer-size

int

r/w/c

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

Gio.FilterInputStream

r

Class Details

class Gio.BufferedInputStream(**kwargs)
Bases:

Gio.FilterInputStream, Gio.Seekable

Abstract:

No

Structure:

Gio.BufferedInputStreamClass

Buffered input stream implements Gio.FilterInputStream and provides for buffered reads.

By default, GBufferedInputStream’s buffer size is set at 4 kilobytes.

To create a buffered input stream, use [ctor`Gio`.BufferedInputStream.new], or [ctor`Gio`.BufferedInputStream.new_sized] to specify the buffer’s size at construction.

To get the size of a buffer within a buffered input stream, use [method`Gio`.BufferedInputStream.get_buffer_size]. To change the size of a buffered input stream’s buffer, use [method`Gio`.BufferedInputStream.set_buffer_size]. Note that the buffer’s size cannot be reduced below the size of the data within the buffer.

classmethod new(base_stream)[source]
Parameters:

base_stream (Gio.InputStream) – a Gio.InputStream

Returns:

a Gio.InputStream for the given base_stream.

Return type:

Gio.InputStream

Creates a new Gio.InputStream from the given base_stream, with a buffer set to the default size (4 kilobytes).

classmethod new_sized(base_stream, size)[source]
Parameters:
Returns:

a Gio.InputStream.

Return type:

Gio.InputStream

Creates a new Gio.BufferedInputStream from the given base_stream, with a buffer set to size.

fill(count, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

the number of bytes read into self's buffer, up to count, or -1 on error.

Return type:

int

Tries to read count bytes from the stream into the buffer. Will block during this read.

If count is zero, returns zero and does nothing. A value of count larger than GObject.G_MAXSSIZE will cause a Gio.IOErrorEnum.INVALID_ARGUMENT error.

On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if count is zero), but never otherwise.

If count is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

For the asynchronous, non-blocking, version of this function, see Gio.BufferedInputStream.fill_async().

fill_async(count, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Reads data into self's buffer asynchronously, up to count size. io_priority can be used to prioritize reads. For the synchronous version of this function, see Gio.BufferedInputStream.fill().

If count is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

fill_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a #gssize of the read stream, or -1 on an error.

Return type:

int

Finishes an asynchronous read.

get_available()[source]
Returns:

size of the available stream.

Return type:

int

Gets the size of the available data within the stream.

get_buffer_size()[source]
Returns:

the current buffer size.

Return type:

int

Gets the size of the input buffer.

peek(buffer, offset)[source]
Parameters:
  • buffer (bytes) – a pointer to an allocated chunk of memory

  • offset (int) – a #gsize

Returns:

a #gsize of the number of bytes peeked, or -1 on error.

Return type:

int

Peeks in the buffer, copying data of size count into buffer, offset offset bytes.

peek_buffer()[source]
Returns:

read-only buffer

Return type:

bytes

Returns the buffer with the currently available bytes. The returned buffer must not be modified and will become invalid when reading from the stream or filling the buffer.

read_byte(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

the byte read from the self, or -1 on end of stream or error.

Return type:

int

Tries to read a single byte from the stream or the buffer. Will block during this read.

On success, the byte read from the stream is returned. On end of stream -1 is returned but it’s not an exceptional error and error is not set.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

set_buffer_size(size)[source]
Parameters:

size (int) – a #gsize

Sets the size of the internal buffer of self to size, or to the size of the contents of the buffer. The buffer can never be resized smaller than its current contents.

do_fill(count, cancellable) virtual
Parameters:
Returns:

the number of bytes read into stream's buffer, up to count, or -1 on error.

Return type:

int

Tries to read count bytes from the stream into the buffer. Will block during this read.

If count is zero, returns zero and does nothing. A value of count larger than GObject.G_MAXSSIZE will cause a Gio.IOErrorEnum.INVALID_ARGUMENT error.

On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if count is zero), but never otherwise.

If count is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

For the asynchronous, non-blocking, version of this function, see Gio.BufferedInputStream.fill_async().

do_fill_async(count, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Reads data into stream's buffer asynchronously, up to count size. io_priority can be used to prioritize reads. For the synchronous version of this function, see Gio.BufferedInputStream.fill().

If count is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

do_fill_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a #gssize of the read stream, or -1 on an error.

Return type:

int

Finishes an asynchronous read.

Property Details

Gio.BufferedInputStream.props.buffer_size
Name:

buffer-size

Type:

int

Default Value:

4096

Flags:

READABLE, WRITABLE, CONSTRUCT

The size of the backend buffer, in bytes.