Gio.BufferedInputStream¶
class — extends FilterInputStream, 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 BufferedInputStream.new,
or BufferedInputStream.new_sized to specify the buffer's size at
construction.
To get the size of a buffer within a buffered input stream, use
BufferedInputStream.get_buffer_size. To change the size of a
buffered input stream's buffer, use BufferedInputStream.set_buffer_size.
Note that the buffer's size cannot be reduced below the size of the data within the buffer.
Constructors¶
new¶
Creates a new InputStream from the given base_stream, with
a buffer set to the default size (4 kilobytes).
Parameters:
base_stream— aInputStream
new_sized¶
Creates a new BufferedInputStream from the given base_stream,
with a buffer set to size.
Parameters:
base_stream— aInputStreamsize— a #gsize
Methods¶
fill¶
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 G_MAXSSIZE will cause a
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 NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error 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
BufferedInputStream.fill_async.
Parameters:
count— the number of bytes that will be read from the streamcancellable— optionalCancellableobject,NULLto ignore
fill_async¶
def fill_async(self, count: int, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[BufferedInputStream | None, AsyncResult], None] | None = ...) -> None
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 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.
Parameters:
count— the number of bytes that will be read from the streamio_priority— the I/O priority of the requestcancellable— optionalCancellableobjectcallback— aAsyncReadyCallback
fill_finish¶
Finishes an asynchronous read.
Parameters:
result— aAsyncResult
get_available¶
Gets the size of the available data within the stream.
get_buffer_size¶
Gets the size of the input buffer.
peek¶
Peeks in the buffered input, copying count bytes of data from offset bytes
in the buffered input into buffer.
Parameters:
buffer— a pointer to an allocated chunk of memory, which must be at leastcountbytes longoffset— offset into the buffered input to peek from, or zero to peek from the next byte in the buffered input onwards
peek_buffer¶
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¶
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 NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error 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.
Parameters:
cancellable— optionalCancellableobject,NULLto ignore
set_buffer_size¶
Sets the size of the internal buffer of stream to size, or to the
size of the contents of the buffer. The buffer can never be resized
smaller than its current contents.
Parameters:
size— a #gsize
Virtual methods¶
do_fill¶
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 G_MAXSSIZE will cause a
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 NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error 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
BufferedInputStream.fill_async.
Parameters:
count— the number of bytes that will be read from the streamcancellable— optionalCancellableobject,NULLto ignore
do_fill_async¶
def do_fill_async(self, count: int, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[BufferedInputStream | None, AsyncResult], None] | None = ...) -> None
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 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.
Parameters:
count— the number of bytes that will be read from the streamio_priority— the I/O priority of the requestcancellable— optionalCancellableobjectcallback— aAsyncReadyCallback
do_fill_finish¶
Finishes an asynchronous read.
Parameters:
result— aAsyncResult
Properties¶
buffer_size¶
The size of the backend buffer, in bytes.