Gio.InputStream¶
| Subclasses: | Gio.FileInputStream,Gio.FilterInputStream,Gio.MemoryInputStream,Gio.UnixInputStream | 
|---|
Methods¶
| Inherited: | GObject.Object (37) | 
|---|---|
| Structs: | GObject.ObjectClass (5) | 
| clear_pending() | |
| close(cancellable) | |
| close_async(io_priority, cancellable, callback, *user_data) | |
| close_finish(result) | |
| has_pending() | |
| is_closed() | |
| read(cancellable) | |
| read_all(cancellable) | |
| read_all_async(io_priority, cancellable, callback, *user_data) | |
| read_all_finish(result) | |
| read_async(io_priority, cancellable, callback, *user_data) | |
| read_bytes(count, cancellable) | |
| read_bytes_async(count, io_priority, cancellable, callback, *user_data) | |
| read_bytes_finish(result) | |
| read_finish(result) | |
| set_pending() | |
| skip(count, cancellable) | |
| skip_async(count, io_priority, cancellable, callback, *user_data) | |
| skip_finish(result) | 
Virtual Methods¶
| Inherited: | GObject.Object (7) | 
|---|
| do_close_async(io_priority, cancellable, callback, *user_data) | |
| do_close_finish(result) | |
| do_close_fn(cancellable) | |
| do_read_async(io_priority, cancellable, callback, *user_data) | |
| do_read_finish(result) | |
| do_read_fn(buffer, count, cancellable) | |
| do_skip(count, cancellable) | |
| do_skip_async(count, io_priority, cancellable, callback, *user_data) | |
| do_skip_finish(result) | 
Properties¶
None
Signals¶
| Inherited: | GObject.Object (1) | 
|---|
Class Details¶
- 
class Gio.InputStream(**kwargs)¶
- Bases: - GObject.Object- Abstract: - Yes - Structure: - Gio.InputStreamClass- Gio.InputStreamhas functions to read from a stream (- Gio.InputStream.read()), to close a stream (- Gio.InputStream.close()) and to skip some content (- Gio.InputStream.skip()).- To copy the content of an input stream to an output stream without manually handling the reads and writes, use - Gio.OutputStream.splice().- See the documentation for - Gio.IOStreamfor details of thread safety of streaming APIs.- All of these functions have async variants too. - 
close(cancellable)[source]¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) – optional- Gio.Cancellableobject,- Noneto ignore.- Raises: - GLib.Error- Returns: - Trueon success,- Falseon failure- Return type: - bool- Closes the stream, releasing resources related to it. - Once the stream is closed, all other operations will return - Gio.IOErrorEnum.CLOSED. Closing a stream multiple times will not return an error.- Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible. - Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details. - On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return - Gio.IOErrorEnum.CLOSEDfor all operations. Still, it is important to check and report the error to the user.- 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.CANCELLEDwill be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn’t block to e.g. check errors.
 - 
close_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - io_priority (int) – the I/O priority of the request
- cancellable (Gio.CancellableorNone) – optional cancellable object
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Requests an asynchronous closes of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call - Gio.InputStream.close_finish() to get the result of the operation.- For behaviour details see - Gio.InputStream.close().- The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. 
- io_priority (
 - 
close_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - Trueif the stream was closed successfully.- Return type: - bool- Finishes closing a stream asynchronously, started from - Gio.InputStream.close_async().
 - 
has_pending()[source]¶
- Returns: - Trueif self has pending actions.- Return type: - bool- Checks if an input stream has pending actions. 
 - 
is_closed()[source]¶
- Returns: - Trueif the stream is closed.- Return type: - bool- Checks if an input stream is closed. 
 - 
read(cancellable)[source]¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) – optional- Gio.Cancellableobject,- Noneto ignore.- Raises: - GLib.Error- Returns: - Number of bytes read, or -1 on error, or 0 on end of file. - buffer: - a buffer to read data into (which should be at least count bytes long). - Return type: - ( - int, buffer:- bytes)- Tries to read count bytes from the stream into the buffer starting at buffer. Will block during this read. - If count is zero returns zero and does nothing. A value of count larger than - GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_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 count is zero), but never otherwise. - The returned buffer is not a nul-terminated string, it can contain nul bytes at any position, and this function doesn’t nul-terminate 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.CANCELLEDwill 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. 
 - 
read_all(cancellable)[source]¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) – optional- Gio.Cancellableobject,- Noneto ignore.- Raises: - GLib.Error- Returns: - Trueon success,- Falseif there was an error- buffer: - a buffer to read data into (which should be at least count bytes long). - bytes_read: - location to store the number of bytes that was read from the stream - Return type: - ( - bool, buffer:- bytes, bytes_read:- int)- Tries to read count bytes from the stream into the buffer starting at buffer. Will block during this read. - This function is similar to - Gio.InputStream.read(), except it tries to read as many bytes as requested, only stopping on an error or end of stream.- On a successful read of count bytes, or if we reached the end of the stream, - Trueis returned, and bytes_read is set to the number of bytes read into buffer.- If there is an error during the operation - Falseis returned and error is set to indicate the error status.- As a special exception to the normal conventions for functions that use - GLib.Error, if this function returns- False(and sets error) then bytes_read will be set to the number of bytes that were successfully read before the error was encountered. This functionality is only available from C. If you need it from another language then you must write your own loop around- Gio.InputStream.read().
 - 
read_all_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - io_priority (int) – the I/O priority of the request
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Returns: - a buffer to read data into (which should be at least count bytes long) - Return type: - buffer: - bytes- Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. - This is the asynchronous equivalent of - Gio.InputStream.read_all().- Call - Gio.InputStream.read_all_finish() to collect the result.- Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is - GLib.PRIORITY_DEFAULT.- New in version 2.44. 
- io_priority (
 - 
read_all_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult- Raises: - GLib.Error- Returns: - Trueon success,- Falseif there was an error- bytes_read: - location to store the number of bytes that was read from the stream - Return type: - ( - bool, bytes_read:- int)- Finishes an asynchronous stream read operation started with - Gio.InputStream.read_all_async().- As a special exception to the normal conventions for functions that use - GLib.Error, if this function returns- False(and sets error) then bytes_read will be set to the number of bytes that were successfully read before the error was encountered. This functionality is only available from C. If you need it from another language then you must write your own loop around- Gio.InputStream.read_async().- New in version 2.44. 
 - 
read_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - io_priority (int) – the I/O priority of the request.
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Returns: - a buffer to read data into (which should be at least count bytes long). - Return type: - buffer: - bytes- Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. When the operation is finished callback will be called. You can then call - Gio.InputStream.read_finish() to get the result of the operation.- During an async request no other sync and async calls are allowed on self, and will result in - Gio.IOErrorEnum.PENDINGerrors.- A value of count larger than - GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_ARGUMENTerror.- On success, the number of bytes read into the buffer will be passed to the callback. 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, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. - Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is - GLib.PRIORITY_DEFAULT.- The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. 
- io_priority (
 - 
read_bytes(count, cancellable)[source]¶
- Parameters: - count (int) – maximum number of bytes that will be read from the stream. Common values include 4096 and 8192.
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
 - Raises: - Returns: - a new - GLib.Bytes, or- Noneon error- Return type: - Like - Gio.InputStream.read(), this tries to read count bytes from the stream in a blocking fashion. However, rather than reading into a user-supplied buffer, this will create a new- GLib.Bytescontaining the data that was read. This may be easier to use from language bindings.- If count is zero, returns a zero-length - GLib.Bytesand does nothing. A value of count larger than- GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_ARGUMENTerror.- On success, a new - GLib.Bytesis returned. It is not an error if the size of this object is not the same as the requested size, as it can happen e.g. near the end of a file. A zero-length- GLib.Bytesis returned on end of file (or if count is zero), but never otherwise.- 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.CANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.- On error - Noneis returned and error is set accordingly.- New in version 2.34. 
- count (
 - 
read_bytes_async(count, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - count (int) – the number of bytes that will be read from the stream
- io_priority (int) – the I/O priority of the request
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Request an asynchronous read of count bytes from the stream into a new - GLib.Bytes. When the operation is finished callback will be called. You can then call- Gio.InputStream.read_bytes_finish() to get the result of the operation.- During an async request no other sync and async calls are allowed on self, and will result in - Gio.IOErrorEnum.PENDINGerrors.- A value of count larger than - GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_ARGUMENTerror.- On success, the new - GLib.Byteswill be passed to the callback. It is not an error if this is smaller than the requested size, as it can happen e.g. near the end of a file, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise.- Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is - GLib.PRIORITY_DEFAULT.- New in version 2.34. 
- count (
 - 
read_bytes_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - the newly-allocated - GLib.Bytes, or- Noneon error- Return type: - GLib.Bytes- Finishes an asynchronous stream read-into- - GLib.Bytesoperation.- New in version 2.34. 
 - 
read_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - number of bytes read in, or -1 on error, or 0 on end of file. - Return type: - int- Finishes an asynchronous stream read operation. 
 - 
set_pending()[source]¶
- Raises: - GLib.Error- Returns: - Trueif pending was previously unset and is now set.- Return type: - bool- Sets self to have actions pending. If the pending flag is already set or self is closed, it will return - Falseand set error.
 - 
skip(count, cancellable)[source]¶
- Parameters: - count (int) – the number of bytes that will be skipped from the stream
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
 - Raises: - Returns: - Number of bytes skipped, or -1 on error - Return type: - Tries to skip count bytes from the stream. Will block during the operation. - This is identical to - Gio.InputStream.read(), from a behaviour standpoint, but the bytes that are skipped are not returned to the user. Some streams have an implementation that is more efficient than reading the data.- This function is optional for inherited classes, as the default implementation emulates it using read. - 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.CANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.
- count (
 - 
skip_async(count, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - count (int) – the number of bytes that will be skipped from the stream
- io_priority (int) – the I/O priority of the request
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Request an asynchronous skip of count bytes from the stream. When the operation is finished callback will be called. You can then call - Gio.InputStream.skip_finish() to get the result of the operation.- During an async request no other sync and async calls are allowed, and will result in - Gio.IOErrorEnum.PENDINGerrors.- A value of count larger than - GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_ARGUMENTerror.- On success, the number of bytes skipped will be passed to the callback. 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, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. - Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is - GLib.PRIORITY_DEFAULT.- The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one, you must override all. 
- count (
 - 
skip_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - the size of the bytes skipped, or - -1on error.- Return type: - int- Finishes a stream skip operation. 
 - 
do_close_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters: - io_priority (int) – the I/O priority of the request
- cancellable (Gio.CancellableorNone) – optional cancellable object
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Requests an asynchronous closes of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call - Gio.InputStream.close_finish() to get the result of the operation.- For behaviour details see - Gio.InputStream.close().- The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. 
- io_priority (
 - 
do_close_finish(result) virtual¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Returns: - Trueif the stream was closed successfully.- Return type: - bool- Finishes closing a stream asynchronously, started from - Gio.InputStream.close_async().
 - 
do_close_fn(cancellable) virtual¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) –- Return type: - bool
 - 
do_read_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters: - io_priority (int) – the I/O priority of the request.
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Returns: - a buffer to read data into (which should be at least count bytes long). - Return type: - buffer: - bytes- Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. When the operation is finished callback will be called. You can then call - Gio.InputStream.read_finish() to get the result of the operation.- During an async request no other sync and async calls are allowed on stream, and will result in - Gio.IOErrorEnum.PENDINGerrors.- A value of count larger than - GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_ARGUMENTerror.- On success, the number of bytes read into the buffer will be passed to the callback. 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, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. - Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is - GLib.PRIORITY_DEFAULT.- The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. 
- io_priority (
 - 
do_read_finish(result) virtual¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Returns: - number of bytes read in, or -1 on error, or 0 on end of file. - Return type: - int- Finishes an asynchronous stream read operation. 
 - 
do_read_fn(buffer, count, cancellable) virtual¶
- Parameters: - buffer (objectorNone) –
- count (int) –
- cancellable (Gio.CancellableorNone) –
 - Return type: 
- buffer (
 - 
do_skip(count, cancellable) virtual¶
- Parameters: - count (int) – the number of bytes that will be skipped from the stream
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
 - Returns: - Number of bytes skipped, or -1 on error - Return type: - Tries to skip count bytes from the stream. Will block during the operation. - This is identical to - Gio.InputStream.read(), from a behaviour standpoint, but the bytes that are skipped are not returned to the user. Some streams have an implementation that is more efficient than reading the data.- This function is optional for inherited classes, as the default implementation emulates it using read. - 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.CANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.
- count (
 - 
do_skip_async(count, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters: - count (int) – the number of bytes that will be skipped from the stream
- io_priority (int) – the I/O priority of the request
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - Request an asynchronous skip of count bytes from the stream. When the operation is finished callback will be called. You can then call - Gio.InputStream.skip_finish() to get the result of the operation.- During an async request no other sync and async calls are allowed, and will result in - Gio.IOErrorEnum.PENDINGerrors.- A value of count larger than - GObject.G_MAXSSIZEwill cause a- Gio.IOErrorEnum.INVALID_ARGUMENTerror.- On success, the number of bytes skipped will be passed to the callback. 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, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. - Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is - GLib.PRIORITY_DEFAULT.- The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one, you must override all. 
- count (
 - 
do_skip_finish(result) virtual¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Returns: - the size of the bytes skipped, or - -1on error.- Return type: - int- Finishes a stream skip operation. 
 
-