Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: OutputStream

[22:7] extends: object

GOutputStream is a base class for implementing streaming output. It has functions to write to a stream ([method@Gio.OutputStream.write]), to close a stream ([method@Gio.OutputStream.close]) and to flush pending writes ([method@Gio.OutputStream.flush]). To copy the content of an input stream to an output stream without manually handling the reads and writes, use [method@Gio.OutputStream.splice]. See the documentation for [class@Gio.IOStream] for details of thread safety of streaming APIs. All of these functions have async variants too. All classes derived from GOutputStream should implement synchronous writing, splicing, flushing and closing streams, but may implement asynchronous versions.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • OutputStream (Handle = null)

    Creates a new OutputStream by wrapping a native handle or another wrapper.

    • @p Handle is the native handle or another wrapper whose handle to adopt.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asObject ()

    Wraps this handle as Object.

    • @r A Object object.
  • clear_pending ()

    Clears the pending flag on @stream.

    • @r None.
  • close (object cancellable)

    Closes the stream, releasing resources related to it. Once the stream is closed, all other operations will return %G_IO_ERROR_CLOSED. Closing a stream multiple times will not return an error. 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 %G_IO_ERROR_CLOSED for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written. 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 %G_IO_ERROR_CANCELLED will be returned. Cancelling a close will still leave the stream closed, but there some streams can use a faster close that doesn't block to e.g. check errors. On cancellation (as with any error) there is no guarantee that all written data will reach the target.

    • @p cancellable is optional cancellable object.
  • close_finish (object result)

    Closes an output stream.

    • @p result is a #GAsyncResult..
  • flush (object cancellable)

    Forces a write of all user-space buffered data for the given @stream. Will block during the operation. Closing the stream will implicitly cause a flush. This function is optional for inherited classes. 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 %G_IO_ERROR_CANCELLED will be returned.

    • @p cancellable is optional cancellable object.
  • flush_finish (object result)

    Finishes flushing an output stream.

    • @p result is a GAsyncResult..
  • has_pending ()

    Checks if an output stream has pending actions.

  • is_closed ()

    Checks if an output stream has already been closed.

  • is_closing ()

    Checks if an output stream is being closed. This can be used inside e.g. a flush implementation to see if the flush (or other i/o operation) is called from within the closing operation.

  • set_pending ()

    Sets @stream to have actions pending. If the pending flag is already set or @stream is closed, it will return %FALSE and set @error.

  • splice (object source, string flags, object cancellable)

    Splices an input stream into an output stream.

    • @p source is a #GInputStream..
    • @p flags is a set of #GOutputStreamSpliceFlags..
    • @p cancellable is optional #GCancellable object, %NULL to ignore..
  • splice_finish (object result)

    Finishes an asynchronous stream splice operation.

    • @p result is a #GAsyncResult..
  • write_bytes (object bytes, object cancellable)

    A wrapper function for g_output_stream_write() which takes a #GBytes as input. This can be more convenient for use by language bindings or in other cases where the refcounted nature of #GBytes is helpful over a bare pointer interface. However, note that this function may still perform partial writes, just like g_output_stream_write(). If that occurs, to continue writing, you will need to create a new #GBytes containing just the remaining bytes, using g_bytes_new_from_bytes(). Passing the same #GBytes instance multiple times potentially can result in duplicated data in the output stream.

    • @p bytes is the #GBytes to write.
    • @p cancellable is optional cancellable object.
  • write_bytes_finish (object result)

    Finishes a stream write-from-#GBytes operation.

    • @p result is a #GAsyncResult..
  • write_finish (object result)

    Finishes a stream write operation.

    • @p result is a #GAsyncResult..