Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: InputStream

[19:7] extends: object

GInputStream is a base class for implementing streaming input. It has functions to read from a stream ([method@Gio.InputStream.read]), to close a stream ([method@Gio.InputStream.close]) and to skip some content ([method@Gio.InputStream.skip]). 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.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • InputStream (Handle = null)

    Creates a new InputStream 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. 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. 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 some streams can use a faster close that doesn't block to e.g. check errors.

    • @p cancellable is optional #GCancellable object, %NULL to ignore..
  • close_finish (object result)

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

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

    Checks if an input stream has pending actions.

  • is_closed ()

    Checks if an input stream is closed.

  • read_bytes (int count, object 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 #GBytes containing the data that was read. This may be easier to use from language bindings. If count is zero, returns a zero-length #GBytes and does nothing. A value of

    • @count larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error. On success, a new #GBytes 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 #GBytes is returned on end of file (or if @count is zero), but never otherwise. 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. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. On error %NULL is returned and @error is set accordingly.
    • @p count is maximum number of bytes that will be read from the stream. Common values include 4096 and 8192..
    • @p cancellable is optional #GCancellable object, %NULL to ignore..
  • read_bytes_finish (object result)

    Finishes an asynchronous stream read-into-#GBytes operation.

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

    Finishes an asynchronous stream read operation.

    • @p result is a #GAsyncResult..
  • 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.

  • skip (int count, object 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. 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. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

    • @p count is the number of bytes that will be skipped from the stream.
    • @p cancellable is optional #GCancellable object, %NULL to ignore..
  • skip_finish (object result)

    Finishes a stream skip operation.

    • @p result is a #GAsyncResult..