BufferedInputStream#
Superclasses: FilterInputStream, InputStream, Object
Subclasses: DataInputStream
Implemented Interfaces: Seekable
Buffered input stream implements FilterInputStream and provides
for buffered reads.
By default, GBufferedInputStream's buffer size is set at 4 kilobytes.
To create a buffered input stream, use new,
or new_sized to specify the buffer’s size at
construction.
To get the size of a buffer within a buffered input stream, use
get_buffer_size. To change the size of a
buffered input stream’s buffer, use set_buffer_size.
Note that the buffer’s size cannot be reduced below the size of the data within the buffer.
Constructors#
- class BufferedInputStream
- classmethod new(base_stream: InputStream) InputStream#
Creates a new
InputStreamfrom the givenbase_stream, with a buffer set to the default size (4 kilobytes).- Parameters:
base_stream – a
InputStream
- classmethod new_sized(base_stream: InputStream, size: int) InputStream#
Creates a new
BufferedInputStreamfrom the givenbase_stream, with a buffer set tosize.- Parameters:
base_stream – a
InputStreamsize – a
gsize
Methods#
- class BufferedInputStream
- do_fill(self, count: int, cancellable: Cancellable | None = None) int#
- Parameters:
count
cancellable
- do_fill_async(self, count: int, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
count
io_priority
cancellable
callback
user_data
- do_fill_finish(self, result: AsyncResult) int#
- Parameters:
result
- fill(count: int, cancellable: Cancellable | None = None) int#
Tries to read
countbytes from the stream into the buffer. Will block during this read.If
countis zero, returns zero and does nothing. A value ofcountlarger thanG_MAXSSIZEwill cause aINVALID_ARGUMENTerror.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
countis zero), but never otherwise.If
countis -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.If
cancellableis notNULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1is returned anderroris set accordingly.For the asynchronous, non-blocking, version of this function, see
fill_async.- Parameters:
count – the number of bytes that will be read from the stream
cancellable – optional
Cancellableobject,NULLto ignore
- async fill_async(self, count: int, io_priority: int) int#
This is the awaitable version of
fill_async().- Parameters:
count – the number of bytes that will be read from the stream
io_priority – the I/O priority of the request
- fill_async(count: int, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Reads data into
stream's buffer asynchronously, up tocountsize.io_prioritycan be used to prioritize reads. For the synchronous version of this function, seefill.If
countis-1then the attempted read size is equal to the number of bytes that are required to fill the buffer.- Parameters:
count – the number of bytes that will be read from the stream
io_priority – the I/O priority of the request
cancellable – optional
Cancellableobjectcallback – a [callback``Gio``.AsyncReadyCallback]
user_data – a
gpointer
- fill_finish(result: AsyncResult) int#
Finishes an asynchronous read.
- Parameters:
result – a
AsyncResult
- peek(buffer: list[int], offset: int) int#
Peeks in the buffer, copying data of size
countintobuffer, offsetoffsetbytes.- Parameters:
buffer – a pointer to an allocated chunk of memory
offset – a
gsize
- peek_buffer() list[int]#
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: Cancellable | None = None) 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
-1is returned but it’s not an exceptional error anderroris not set.If
cancellableis notNULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1is returned anderroris set accordingly.- Parameters:
cancellable – optional
Cancellableobject,NULLto ignore
Properties#
Virtual Methods#
- class BufferedInputStream
- do_fill(count: int, cancellable: Cancellable | None = None) int#
Tries to read
countbytes from the stream into the buffer. Will block during this read.If
countis zero, returns zero and does nothing. A value ofcountlarger thanG_MAXSSIZEwill cause aINVALID_ARGUMENTerror.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
countis zero), but never otherwise.If
countis -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.If
cancellableis notNULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1is returned anderroris set accordingly.For the asynchronous, non-blocking, version of this function, see
fill_async.- Parameters:
count – the number of bytes that will be read from the stream
cancellable – optional
Cancellableobject,NULLto ignore
- do_fill_async(count: int, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Reads data into
stream's buffer asynchronously, up tocountsize.io_prioritycan be used to prioritize reads. For the synchronous version of this function, seefill.If
countis-1then the attempted read size is equal to the number of bytes that are required to fill the buffer.- Parameters:
count – the number of bytes that will be read from the stream
io_priority – the I/O priority of the request
cancellable – optional
Cancellableobjectcallback – a [callback``Gio``.AsyncReadyCallback]
user_data – a
gpointer
- do_fill_finish(result: AsyncResult) int#
Finishes an asynchronous read.
- Parameters:
result – a
AsyncResult