Synopsis#include <gio/gio.h> enum GOutputStreamSpliceFlags; GOutputStream; gssize g_output_stream_write (GOutputStream *stream, const void *buffer, gsize count, GCancellable *cancellable, GError **error); gboolean g_output_stream_write_all (GOutputStream *stream, const void *buffer, gsize count, gsize *bytes_written, GCancellable *cancellable, GError **error); gssize g_output_stream_splice (GOutputStream *stream, GInputStream *source, GOutputStreamSpliceFlags flags, GCancellable *cancellable, GError **error); gboolean g_output_stream_flush (GOutputStream *stream, GCancellable *cancellable, GError **error); gboolean g_output_stream_close (GOutputStream *stream, GCancellable *cancellable, GError **error); void g_output_stream_write_async (GOutputStream *stream, const void *buffer, gsize count, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gssize g_output_stream_write_finish (GOutputStream *stream, GAsyncResult *result, GError **error); void g_output_stream_splice_async (GOutputStream *stream, GInputStream *source, GOutputStreamSpliceFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gssize g_output_stream_splice_finish (GOutputStream *stream, GAsyncResult *result, GError **error); void g_output_stream_flush_async (GOutputStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_output_stream_flush_finish (GOutputStream *stream, GAsyncResult *result, GError **error); void g_output_stream_close_async (GOutputStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_output_stream_close_finish (GOutputStream *stream, GAsyncResult *result, GError **error); gboolean g_output_stream_is_closed (GOutputStream *stream); gboolean g_output_stream_has_pending (GOutputStream *stream); gboolean g_output_stream_set_pending (GOutputStream *stream, GError **error); void g_output_stream_clear_pending (GOutputStream *stream); Object HierarchyGObject +----GOutputStream +----GFilterOutputStream +----GFileOutputStream +----GMemoryOutputStream +----GUnixOutputStream Description
GOutputStream has functions to write to a stream (
To copy the content of an input stream to an output stream without
manually handling the reads and writes, use All of these functions have async variants too.
Detailsenum GOutputStreamSpliceFlagstypedef enum { G_OUTPUT_STREAM_SPLICE_NONE = 0, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE = (1 << 0), G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET = (1 << 1) } GOutputStreamSpliceFlags; GOutputStreamSpliceFlags determine how streams should be spliced.
GOutputStreamtypedef struct _GOutputStream GOutputStream; Base class for writing output. All classes derived from GOutputStream should implement synchronous writing, splicing, flushing and closing streams, but may implement asynchronous versions.
g_output_stream_write ()gssize g_output_stream_write (GOutputStream *stream, const void *buffer, gsize count, GCancellable *cancellable, GError **error);
Tries to write
If count is zero returns zero and does nothing. A value of
On success, the number of bytes written to the stream is returned.
It is not an error if this is not the same as the requested size, as it
can happen e.g. on a partial i/o error, or if there is not enough
storage in the stream. All writes either block until at least one byte
is written, so zero is never returned (unless
If
On error -1 is returned and
g_output_stream_write_all ()gboolean g_output_stream_write_all (GOutputStream *stream, const void *buffer, gsize count, gsize *bytes_written, GCancellable *cancellable, GError **error);
Tries to write
This function is similar to
On a successful write of
If there is an error during the operation FALSE is returned and
g_output_stream_splice ()gssize g_output_stream_splice (GOutputStream *stream, GInputStream *source, GOutputStreamSpliceFlags flags, GCancellable *cancellable, GError **error); Splices an input stream into an output stream.
g_output_stream_flush ()gboolean g_output_stream_flush (GOutputStream *stream, GCancellable *cancellable, GError **error); Flushed any outstanding buffers in the stream. Will block during the operation. Closing the stream will implicitly cause a flush. This function is optional for inherited classes.
If
g_output_stream_close ()gboolean g_output_stream_close (GOutputStream *stream, GCancellable *cancellable, GError **error); Closes the stream, releasing resources related to it.
Once the stream is closed, all other operations will return Closing a stream will automatically flush any outstanding buffers in the stream. 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
If
g_output_stream_write_async ()void g_output_stream_write_async (GOutputStream *stream, const void *buffer, gsize count, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Request an asynchronous write of
During an async request no other sync and async calls are allowed,
and will result in
A value of
On success, the number of bytes written will be passed to the
Any outstanding I/O request with higher priority (lower numerical
value) will be executed before an outstanding request with lower
priority. Default priority is 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.
For the synchronous, blocking version of this function, see
g_output_stream_write_finish ()gssize g_output_stream_write_finish (GOutputStream *stream, GAsyncResult *result, GError **error); Finishes a stream write operation.
g_output_stream_splice_async ()void g_output_stream_splice_async (GOutputStream *stream, GInputStream *source, GOutputStreamSpliceFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Splices a stream asynchronously.
When the operation is finished
For the synchronous, blocking version of this function, see
g_output_stream_splice_finish ()gssize g_output_stream_splice_finish (GOutputStream *stream, GAsyncResult *result, GError **error); Finishes an asynchronous stream splice operation.
g_output_stream_flush_async ()void g_output_stream_flush_async (GOutputStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Flushes a stream asynchronously.
For behaviour details see
When the operation is finished
g_output_stream_flush_finish ()gboolean g_output_stream_flush_finish (GOutputStream *stream, GAsyncResult *result, GError **error); Finishes flushing an output stream.
g_output_stream_close_async ()void g_output_stream_close_async (GOutputStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Requests an asynchronous close of the stream, releasing resources
related to it. When the operation is finished
For behaviour details see 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.
g_output_stream_close_finish ()gboolean g_output_stream_close_finish (GOutputStream *stream, GAsyncResult *result, GError **error); Closes an output stream.
g_output_stream_is_closed ()gboolean g_output_stream_is_closed (GOutputStream *stream); Checks if an output stream has already been closed.
g_output_stream_has_pending ()gboolean g_output_stream_has_pending (GOutputStream *stream); Checks if an ouput stream has pending actions.
g_output_stream_set_pending ()gboolean g_output_stream_set_pending (GOutputStream *stream, GError **error);
Sets
g_output_stream_clear_pending ()void g_output_stream_clear_pending (GOutputStream *stream);
Clears the pending flag on
|