glibmm: Gio::InputStream Class Reference

glibmm 2.77.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::InputStream Class Reference
Stream Classes

Base class for implementing streaming input. More...

`#include <giomm/inputstream.h>`

Inheritance diagram for Gio::InputStream:
[legend]

## Public Member Functions
| InputStream (InputStream && src) noexcept
InputStream & | operator= (InputStream && src) noexcept
| ~InputStream () noexcept override
GInputStream * | gobj ()
| Provides access to the underlying C GObject. More...
const GInputStream * | gobj () const
| Provides access to the underlying C GObject. More...
GInputStream * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
gssize | read (void * buffer, gsize count, const Glib::RefPtr< Cancellable > & cancellable)
| Tries to read count bytes from the stream into the buffer starting at buffer. More...
gssize | read (void * buffer, gsize count)
| A read() convenience overload. More...
bool | read_all (void * buffer, gsize count, gsize & bytes_read, const Glib::RefPtr< Cancellable > & cancellable)
| Tries to read count bytes from the stream into the buffer starting at buffer. More...
bool | read_all (void * buffer, gsize count, gsize & bytes_read)
| A read_all() convenience overload. More...
Glib::RefPtr< Glib::Bytes > | read_bytes (gsize count, const Glib::RefPtr< Cancellable > & cancellable)
| Like g_input_stream_read(), this tries to read count bytes from the stream in a blocking fashion. More...
void | read_bytes_async (gsize count, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous read of count bytes from the stream into a new Glib::Bytes. More...
void | read_bytes_async (gsize count, const SlotAsyncReady & slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous read of count bytes from the stream into a new Glib::Bytes. More...
Glib::RefPtr< Glib::Bytes > | read_bytes_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an asynchronous stream read-into-Bytes operation. More...
gssize | skip (gsize count, const Glib::RefPtr< Cancellable > & cancellable)
| Tries to skip count bytes from the stream. More...
gssize | skip (gsize count)
| A skip() convenience overload. More...
bool | close (const Glib::RefPtr< Cancellable > & cancellable)
| Closes the stream, releasing resources related to it. More...
bool | close ()
| A close() convenience overload. More...
void | read_async (void * buffer, gsize count, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. More...
void | read_async (void * buffer, gsize count, const SlotAsyncReady & slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. More...
gssize | read_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an asynchronous stream read operation. More...
void | read_all_async (void * buffer, gsize count, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. More...
void | read_all_async (void * buffer, gsize count, const SlotAsyncReady & slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. More...
bool | read_all_finish (const Glib::RefPtr< AsyncResult > & result, gsize & bytes_read)
| Finishes an asynchronous stream read operation started with g_input_stream_read_all_async(). More...
void | skip_async (gsize count, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer. More...
void | skip_async (gsize count, const SlotAsyncReady & slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer. More...
gssize | skip_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes a stream skip operation. More...
void | close_async (const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Requests an asynchronous closes of the stream, releasing resources related to it. More...
void | close_async (const SlotAsyncReady & slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Requests an asynchronous closes of the stream, releasing resources related to it. More...
gboolean | close_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes closing a stream asynchronously, started from g_input_stream_close_async(). More...
bool | is_closed () const
| Checks if an input stream is closed. More...
bool | has_pending () const
| Checks if an input stream has pending actions. More...
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object && src) noexcept
Object & | operator= (Object && src) noexcept
void * | get_data (const QueryQuark & key)
void | set_data (const Quark & key, void *data)
void | set_data_with_c_callback (const Quark & key, void *data, GDestroyNotify notify)
void | set_data (const Quark & key, void *data, DestroyNotify notify)
| Prefer set_data_with_c_callback() with a callback with C linkage. More...
void | remove_data (const QueryQuark & quark)
void * | steal_data (const QueryQuark & quark)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring & property_name, const PropertyType & value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring & property_name, PropertyType & value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
PropertyType | get_property (const Glib::ustring & property_name) const
| You probably want to use a specific property_*() accessor method instead. More...
sigc::connection | connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void()> & slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject * | gobj ()
| Provides access to the underlying C GObject. More...
const GObject * | gobj () const
| Provides access to the underlying C GObject. More...
GObject * | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions
| InputStream ()
bool | set_pending ()
| Sets stream to have actions pending. More...
void | clear_pending ()
| Clears the pending flag on stream. More...
virtual gssize | read_vfunc (void * buffer, gsize count, const Glib::RefPtr< Cancellable > & cancellable)
virtual gssize | skip_vfunc (gsize count, const Glib::RefPtr< Cancellable > & cancellable)
virtual bool | close_vfunc (const Glib::RefPtr< Cancellable > & cancellable)
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams & construct_params)
| Object (GObject * castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char * custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info & custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase && src) noexcept
ObjectBase & | operator= (ObjectBase && src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject * castitem)
void | initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::InputStream > | wrap (GInputStream * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject * object, bool take_copy=false)

## Additional Inherited Members
Public Types inherited from Glib::Object
using | DestroyNotify = void(*)(gpointer data)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

Base class for implementing streaming input.

Since glibmm 2.16:

## Constructor & Destructor Documentation

## ◆ InputStream() [1/2]

Gio::InputStream::InputStream | ( | InputStream && | src | ) |
| noexcept

## ◆ ~InputStream()

Gio::InputStream::~InputStream | ( |  | ) |
| overridenoexcept

## ◆ InputStream() [2/2]

Gio::InputStream::InputStream | ( |  | ) |
| protected

## Member Function Documentation

## ◆ clear_pending()

void Gio::InputStream::clear_pending | ( |  | ) |
| protected

Clears the pending flag on stream.

Since glibmm 2.50:

## ◆ close() [1/2]

bool Gio::InputStream::close | ( |  | ) |

A close() convenience overload.

## ◆ close() [2/2]

bool Gio::InputStream::close | ( | const Glib::RefPtr< Cancellable > & | cancellable | ) |

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will throw a Gio::Error with 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 throw a Gio::Error with CLOSED for all operations. Still, it is important to check and report the error to the user.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. 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.

Parameters

  cancellable | Cancellable object.

Returns
  `true` on success, `false` on failure.

Exceptions

  Glib::Error |

## ◆ close_async() [1/2]

void Gio::InputStream::close_async | ( | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Requests an asynchronous closes of the stream, releasing resources related to it.

When the operation is finished slot will be called. You can then call close_finish() to get the result of the operation.

For behaviour details see close().

The asyncronous 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.

Parameters

  slot | Callback to call when the request is satisfied.
  cancellable | A Cancellable object.
  io_priority | The I/O priority of the request.

## ◆ close_async() [2/2]

void Gio::InputStream::close_async | ( | const SlotAsyncReady & | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Requests an asynchronous closes of the stream, releasing resources related to it.

When the operation is finished slot will be called. You can then call close_finish() to get the result of the operation.

For behaviour details see close().

The asyncronous 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.

Parameters

  slot | Callback to call when the request is satisfied.
  io_priority | The I/O priority of the request.

## ◆ close_finish()

gboolean Gio::InputStream::close_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes closing a stream asynchronously, started from g_input_stream_close_async().

Parameters

  result | A AsyncResult.

Returns
  `true` if the stream was closed successfully.

Exceptions

  Glib::Error |

## ◆ close_vfunc()

virtual bool Gio::InputStream::close_vfunc | ( | const Glib::RefPtr< Cancellable > & | cancellable | ) |
| protectedvirtual

Exceptions

  Glib::Error. |

## ◆ get_type()

static GType Gio::InputStream::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GInputStream * Gio::InputStream::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GInputStream * Gio::InputStream::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GInputStream * Gio::InputStream::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ has_pending()

bool Gio::InputStream::has_pending | ( |  | ) | const

Checks if an input stream has pending actions.

Since glibmm 2.50:

Returns
  `true` if stream has pending actions.

## ◆ is_closed()

bool Gio::InputStream::is_closed | ( |  | ) | const

Checks if an input stream is closed.

Since glibmm 2.50:

Returns
  `true` if the stream is closed.

## ◆ operator=()

InputStream & Gio::InputStream::operator= | ( | InputStream && | src | ) |
| noexcept

## ◆ read() [1/2]

gssize Gio::InputStream::read | ( | void * | buffer,
|  | gsize | count
| ) |  |

A read() convenience overload.

## ◆ read() [2/2]

gssize Gio::InputStream::read | ( | void * | buffer,
|  | gsize | count,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

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 G_MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

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 operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

Parameters

  buffer | A buffer to read data into (which should be at least count bytes long).
  count | The number of bytes that will be read from the stream.
  cancellable | Cancellable object.

Returns
  Number of bytes read, or -1 on error.

Exceptions

  Glib::Error |

## ◆ read_all() [1/2]

bool Gio::InputStream::read_all | ( | void * | buffer,
|  | gsize | count,
|  | gsize & | bytes_read
| ) |  |

A read_all() convenience overload.

## ◆ read_all() [2/2]

bool Gio::InputStream::read_all | ( | void * | buffer,
|  | gsize | count,
|  | gsize & | bytes_read,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

Tries to read count bytes from the stream into the buffer starting at buffer.

Will block during this read.

This function is similar to g_input_stream_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, `true` is returned, and bytes_read is set to the number of bytes read into buffer.

If there is an error during the operation `false` is returned and error is set to indicate the error status.

As a special exception to the normal conventions for functions that use 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 g_input_stream_read().

Parameters

  buffer | A buffer to read data into (which should be at least count bytes long).
  count | The number of bytes that will be read from the stream.
  bytes_read | Location to store the number of bytes that was read from the stream.
  cancellable | Optional Cancellable object, `nullptr` to ignore.

Returns
  `true` on success, `false` if there was an error.

Exceptions

  Glib::Error |

## ◆ read_all_async() [1/2]

void Gio::InputStream::read_all_async | ( | void * | buffer,
|  | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.

This is the asynchronous equivalent of read_all().

When the operation is finished slot will be called. You can then call read_all_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::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer will be passed to the slot 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 PRIORITY_DEFAULT.

The asyncronous 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.

Parameters

  buffer | A buffer to read data into (which should be at least count bytes long).
  count | The number of bytes that will be read from the stream.
  slot | Callback to call when the request is satisfied.
  cancellable | A Cancellable object.
  io_priority | The I/O priority of the request.

## ◆ read_all_async() [2/2]

void Gio::InputStream::read_all_async | ( | void * | buffer,
|  | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.

This is the asynchronous equivalent of read_all().

When the operation is finished slot will be called. You can then call read_all_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in a Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer will be passed to the slot 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 PRIORITY_DEFAULT.

The asyncronous 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.

Parameters

  buffer | A buffer to read data into (which should be at least count bytes long).
  count | The number of bytes that will be read from the stream.
  slot | Callback to call when the request is satisfied.
  io_priority | The I/O priority of the request.

## ◆ read_all_finish()

bool Gio::InputStream::read_all_finish | ( | const Glib::RefPtr< AsyncResult > & | result,
|  | gsize & | bytes_read
| ) |  |

Finishes an asynchronous stream read operation started with g_input_stream_read_all_async().

As a special exception to the normal conventions for functions that use 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 g_input_stream_read_async().

Since glibmm 2.44:

Parameters

  result | A AsyncResult.
  bytes_read | Location to store the number of bytes that was read from the stream.

Returns
  `true` on success, `false` if there was an error.

Exceptions

  Glib::Error |

## ◆ read_async() [1/2]

void Gio::InputStream::read_async | ( | void * | buffer,
|  | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call read_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::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer will be passed to the slot 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 PRIORITY_DEFAULT.

The asyncronous 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.

Parameters

  buffer | A buffer to read data into (which should be at least count bytes long).
  count | The number of bytes that will be read from the stream.
  slot | Callback to call when the request is satisfied.
  cancellable | A Cancellable object.
  io_priority | The I/O priority of the request.

## ◆ read_async() [2/2]

void Gio::InputStream::read_async | ( | void * | buffer,
|  | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call read_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in a Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer will be passed to the slot 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 PRIORITY_DEFAULT.

The asyncronous 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.

Parameters

  buffer | A buffer to read data into (which should be at least count bytes long).
  count | The number of bytes that will be read from the stream.
  slot | Callback to call when the request is satisfied.
  io_priority | The I/O priority of the request.

## ◆ read_bytes()

Glib::RefPtr< Glib::Bytes > Gio::InputStream::read_bytes | ( | gsize | count,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

Like g_input_stream_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 Bytes containing the data that was read. This may be easier to use from language bindings.

If count is zero, returns a zero-length Bytes and does nothing. A value of count larger than G_MAXSSIZE will cause a Gio::Error::INVALID_ARGUMENT error.

On success, a new Bytes is 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 Bytes is returned on end of file (or if count is zero), but never otherwise.

If cancellable is not `nullptr`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio::Error::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 `nullptr` is returned and error is set accordingly.

Since glibmm 2.34:

Parameters

  count | Maximum number of bytes that will be read from the stream. Common values include 4096 and 8192.
  cancellable | Optional Cancellable object, `nullptr` to ignore.

Returns
  A new Bytes, or `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ read_bytes_async() [1/2]

void Gio::InputStream::read_bytes_async | ( | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous read of count bytes from the stream into a new Glib::Bytes.

When the operation is finished slot will be called. You can then call read_bytes_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::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the new Glib::Bytes will 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. The default priority is PRIORITY_DEFAULT.

Parameters

  count | The number of bytes that will be read from the stream.
  slot | Callback to call when the request is satisfied.
  cancellable | A Cancellable object.
  io_priority | The I/O priority of the request.

Since glibmm 2.34:

## ◆ read_bytes_async() [2/2]

void Gio::InputStream::read_bytes_async | ( | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous read of count bytes from the stream into a new Glib::Bytes.

When the operation is finished slot will be called. You can then call read_bytes_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::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the new Glib::Bytes will 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. The default priority is PRIORITY_DEFAULT.

Parameters

  count | The number of bytes that will be read from the stream.
  slot | Callback to call when the request is satisfied.h
  io_priority | The I/O priority of the request.

Since glibmm 2.34:

## ◆ read_bytes_finish()

Glib::RefPtr< Glib::Bytes > Gio::InputStream::read_bytes_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an asynchronous stream read-into-Bytes operation.

Since glibmm 2.34:

Parameters

  result | A AsyncResult.

Returns
  The newly-allocated Bytes, or `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ read_finish()

gssize Gio::InputStream::read_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an asynchronous stream read operation.

Parameters

  result | A AsyncResult.

Returns
  Number of bytes read in, or -1 on error, or 0 on end of file.

Exceptions

  Glib::Error |

## ◆ read_vfunc()

virtual gssize Gio::InputStream::read_vfunc | ( | void * | buffer,
|  | gsize | count,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |
| protectedvirtual

Exceptions

  Glib::Error. |

## ◆ set_pending()

bool Gio::InputStream::set_pending | ( |  | ) |
| protected

Sets stream to have actions pending.

If the pending flag is already set or stream is closed, it will return `false` and set error.

Since glibmm 2.50:

Returns
  `true` if pending was previously unset and is now set.

Exceptions

  Glib::Error |

## ◆ skip() [1/2]

gssize Gio::InputStream::skip | ( | gsize | count | ) |

A skip() convenience overload.

## ◆ skip() [2/2]

gssize Gio::InputStream::skip | ( | gsize | count,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

Tries to skip count bytes from the stream.

Will block during the operation.

This is identical to g_input_stream_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.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

Parameters

  count | The number of bytes that will be skipped from the stream.
  cancellable | Cancellable object.

Returns
  Number of bytes skipped, or -1 on error.

Exceptions

  Glib::Error |

## ◆ skip_async() [1/2]

void Gio::InputStream::skip_async | ( | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call 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::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

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 PRIORITY_DEFAULT.

The asyncronous 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.

Parameters

  count | The number of bytes that will be skipped from the stream.
  slot | Callback to call when the request is satisfied.
  cancellable | A Cancellable object.
  io_priority | The I/O priority of the request.

## ◆ skip_async() [2/2]

void Gio::InputStream::skip_async | ( | gsize | count,
|  | const SlotAsyncReady & | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT`
| ) |  |

Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call 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::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

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 PRIORITY_DEFAULT.

The asyncronous 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.

Parameters

  count | The number of bytes that will be skipped from the stream.
  slot | Callback to call when the request is satisfied.
  io_priority | The I/O priority of the request.

## ◆ skip_finish()

gssize Gio::InputStream::skip_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes a stream skip operation.

Parameters

  result | A AsyncResult.

Returns
  The size of the bytes skipped, or `-1` on error.

Exceptions

  Glib::Error |

## ◆ skip_vfunc()

virtual gssize Gio::InputStream::skip_vfunc | ( | gsize | count,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |
| protectedvirtual

Exceptions

  Glib::Error. |

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gio::InputStream > wrap | ( | GInputStream * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.