:right-sidebar: True OutputStream =================================================================== .. currentmodule:: gi.repository.Gio .. class:: OutputStream(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gio.FileOutputStream`, :class:`~gi.repository.Gio.FilterOutputStream`, :class:`~gi.repository.Gio.MemoryOutputStream`, :class:`~gi.repository.Gio.UnixOutputStream` ``GOutputStream`` is a base class for implementing streaming output. It has functions to write to a stream (:obj:`~gi.repository.Gio.OutputStream.write`\), to close a stream (:obj:`~gi.repository.Gio.OutputStream.close`\) and to flush pending writes (:obj:`~gi.repository.Gio.OutputStream.flush`\). To copy the content of an input stream to an output stream without manually handling the reads and writes, use :obj:`~gi.repository.Gio.OutputStream.splice`\. See the documentation for :obj:`~gi.repository.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. Methods ------- .. rst-class:: interim-class .. class:: OutputStream :no-index: .. method:: clear_pending() -> None Clears the pending flag on ``stream``\. .. method:: close(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Closes the stream, releasing resources related to it. Once the stream is closed, all other operations will return :const:`~gi.repository.Gio.IOErrorEnum.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 :const:`~gi.repository.Gio.IOErrorEnum.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 :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~gi.repository.Gio.IOErrorEnum.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. :param cancellable: optional cancellable object .. method:: close_async(io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.close_finish` to get the result of the operation. For behaviour details see :func:`~gi.repository.Gio.OutputStream.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. :param io_priority: the io priority of the request. :param cancellable: optional cancellable object :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: close_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Closes an output stream. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_close_async(self, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_close_finish(self, result: ~gi.repository.Gio.AsyncResult) -> bool :param result: .. method:: do_close_fn(self, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool :param cancellable: .. method:: do_flush(self, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool :param cancellable: .. method:: do_flush_async(self, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_flush_finish(self, result: ~gi.repository.Gio.AsyncResult) -> bool :param result: .. method:: do_splice(self, source: ~gi.repository.Gio.InputStream, flags: ~gi.repository.Gio.OutputStreamSpliceFlags, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int :param source: :param flags: :param cancellable: .. method:: do_splice_async(self, source: ~gi.repository.Gio.InputStream, flags: ~gi.repository.Gio.OutputStreamSpliceFlags, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None :param source: :param flags: :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_splice_finish(self, result: ~gi.repository.Gio.AsyncResult) -> int :param result: .. method:: do_write_async(self, buffer: list[int] | None, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None :param buffer: :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_write_finish(self, result: ~gi.repository.Gio.AsyncResult) -> int :param result: .. method:: do_write_fn(self, buffer: list[int] | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int :param buffer: :param cancellable: .. method:: do_writev_async(self, vectors: list[~gi.repository.Gio.OutputVector], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None :param vectors: :param io_priority: :param cancellable: :param callback: :param user_data: .. method:: do_writev_finish(self, result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[bool, int] :param result: .. method:: do_writev_fn(self, vectors: list[~gi.repository.Gio.OutputVector], cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[bool, int] :param vectors: :param cancellable: .. method:: flush(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool 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 :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. :param cancellable: optional cancellable object .. method:: flush_async(io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Forces an asynchronous write of all user-space buffered data for the given ``stream``\. For behaviour details see :func:`~gi.repository.Gio.OutputStream.flush`. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.flush_finish` to get the result of the operation. :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: flush_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes flushing an output stream. :param result: a GAsyncResult. .. method:: has_pending() -> bool Checks if an output stream has pending actions. .. method:: is_closed() -> bool Checks if an output stream has already been closed. .. method:: is_closing() -> bool 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. .. versionadded:: 2.24 .. method:: set_pending() -> bool Sets ``stream`` to have actions pending. If the pending flag is already set or ``stream`` is closed, it will return :const:`False` and set ``error``\. .. method:: splice(source: ~gi.repository.Gio.InputStream, flags: ~gi.repository.Gio.OutputStreamSpliceFlags, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Splices an input stream into an output stream. :param source: a :obj:`~gi.repository.Gio.InputStream`\. :param flags: a set of :obj:`~gi.repository.Gio.OutputStreamSpliceFlags`\. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: splice_async(source: ~gi.repository.Gio.InputStream, flags: ~gi.repository.Gio.OutputStreamSpliceFlags, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Splices a stream asynchronously. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.splice_finish` to get the result of the operation. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.splice`. :param source: a :obj:`~gi.repository.Gio.InputStream`\. :param flags: a set of :obj:`~gi.repository.Gio.OutputStreamSpliceFlags`\. :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: splice_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes an asynchronous stream splice operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: write(buffer: list[int], cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Tries to write ``count`` bytes from ``buffer`` into the stream. Will block during the operation. If count is 0, returns 0 and does nothing. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. 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 block until at least one byte is written or an error occurs; 0 is never returned (unless ``count`` is 0). If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~gi.repository.Gio.IOErrorEnum.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 -1 is returned and ``error`` is set accordingly. :param buffer: the buffer containing the data to write. :param cancellable: optional cancellable object .. method:: write_all(buffer: list[int], cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[bool, int] Tries to write ``count`` bytes from ``buffer`` into the stream. Will block during the operation. This function is similar to :func:`~gi.repository.Gio.OutputStream.write`, except it tries to write as many bytes as requested, only stopping on an error. On a successful write of ``count`` bytes, :const:`True` is returned, and ``bytes_written`` is set to ``count``\. If there is an error during the operation :const:`False` is returned and ``error`` is set to indicate the error status. As a special exception to the normal conventions for functions that use :obj:`~gi.repository.GLib.Error`\, if this function returns :const:`False` (and sets ``error``\) then ``bytes_written`` will be set to the number of bytes that were successfully written 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 :func:`~gi.repository.Gio.OutputStream.write`. :param buffer: the buffer containing the data to write. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: write_all_async(buffer: list[int], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Request an asynchronous write of ``count`` bytes from ``buffer`` into the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.write_all_finish` to get the result of the operation. This is the asynchronous version of :func:`~gi.repository.Gio.OutputStream.write_all`. Call :func:`~gi.repository.Gio.OutputStream.write_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 %G_PRIORITY_DEFAULT. Note that no copy of ``buffer`` will be made, so it must stay valid until ``callback`` is called. .. versionadded:: 2.44 :param buffer: the buffer containing the data to write :param io_priority: the io priority of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: write_all_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[bool, int] Finishes an asynchronous stream write operation started with :func:`~gi.repository.Gio.OutputStream.write_all_async`. As a special exception to the normal conventions for functions that use :obj:`~gi.repository.GLib.Error`\, if this function returns :const:`False` (and sets ``error``\) then ``bytes_written`` will be set to the number of bytes that were successfully written 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 :func:`~gi.repository.Gio.OutputStream.write_async`. .. versionadded:: 2.44 :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: write_async(buffer: list[int], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Request an asynchronous write of ``count`` bytes from ``buffer`` into the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.write_finish` to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes written 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. on a partial I/O error, but generally we try to write as many bytes as requested. You are guaranteed that this method will never fail with :const:`~gi.repository.Gio.IOErrorEnum.WOULD_BLOCK` - if ``stream`` can't accept more data, the method will just wait until this changes. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_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. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.write`. Note that no copy of ``buffer`` will be made, so it must stay valid until ``callback`` is called. See :func:`~gi.repository.Gio.OutputStream.write_bytes_async` for a :obj:`~gi.repository.GLib.Bytes` version that will automatically hold a reference to the contents (without copying) for the duration of the call. :param buffer: the buffer containing the data to write. :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: write_bytes(bytes: ~gi.repository.GLib.Bytes, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int A wrapper function for :func:`~gi.repository.Gio.OutputStream.write` which takes a :obj:`~gi.repository.GLib.Bytes` as input. This can be more convenient for use by language bindings or in other cases where the refcounted nature of :obj:`~gi.repository.GLib.Bytes` is helpful over a bare pointer interface. However, note that this function may still perform partial writes, just like :func:`~gi.repository.Gio.OutputStream.write`. If that occurs, to continue writing, you will need to create a new :obj:`~gi.repository.GLib.Bytes` containing just the remaining bytes, using :func:`~gi.repository.GLib.Bytes.new_from_bytes`. Passing the same :obj:`~gi.repository.GLib.Bytes` instance multiple times potentially can result in duplicated data in the output stream. :param bytes: the :obj:`~gi.repository.GLib.Bytes` to write :param cancellable: optional cancellable object .. method:: write_bytes_async(bytes: ~gi.repository.GLib.Bytes, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None This function is similar to :func:`~gi.repository.Gio.OutputStream.write_async`, but takes a :obj:`~gi.repository.GLib.Bytes` as input. Due to the refcounted nature of :obj:`~gi.repository.GLib.Bytes`\, this allows the stream to avoid taking a copy of the data. However, note that this function may still perform partial writes, just like :func:`~gi.repository.Gio.OutputStream.write_async`. If that occurs, to continue writing, you will need to create a new :obj:`~gi.repository.GLib.Bytes` containing just the remaining bytes, using :func:`~gi.repository.GLib.Bytes.new_from_bytes`. Passing the same :obj:`~gi.repository.GLib.Bytes` instance multiple times potentially can result in duplicated data in the output stream. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.write_bytes`. :param bytes: The bytes to write :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: write_bytes_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes a stream write-from-:obj:`~gi.repository.GLib.Bytes` operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: write_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes a stream write operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: writev(vectors: list[~gi.repository.Gio.OutputVector], cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[bool, int] Tries to write the bytes contained in the ``n_vectors`` ``vectors`` into the stream. Will block during the operation. If ``n_vectors`` is 0 or the sum of all bytes in ``vectors`` is 0, returns 0 and does nothing. 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 block until at least one byte is written or an error occurs; 0 is never returned (unless ``n_vectors`` is 0 or the sum of all bytes in ``vectors`` is 0). If ``cancellable`` is not :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. Some implementations of :func:`~gi.repository.Gio.OutputStream.writev` may have limitations on the aggregate buffer size, and will return :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` if these are exceeded. For example, when writing to a local file on UNIX platforms, the aggregate buffer size must not exceed %G_MAXSSIZE bytes. .. versionadded:: 2.60 :param vectors: the buffer containing the :obj:`~gi.repository.Gio.OutputVector` to write. :param cancellable: optional cancellable object .. method:: writev_all(vectors: list[~gi.repository.Gio.OutputVector], cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[bool, int] Tries to write the bytes contained in the ``n_vectors`` ``vectors`` into the stream. Will block during the operation. This function is similar to :func:`~gi.repository.Gio.OutputStream.writev`, except it tries to write as many bytes as requested, only stopping on an error. On a successful write of all ``n_vectors`` vectors, :const:`True` is returned, and ``bytes_written`` is set to the sum of all the sizes of ``vectors``\. If there is an error during the operation :const:`False` is returned and ``error`` is set to indicate the error status. As a special exception to the normal conventions for functions that use :obj:`~gi.repository.GLib.Error`\, if this function returns :const:`False` (and sets ``error``\) then ``bytes_written`` will be set to the number of bytes that were successfully written 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 :func:`~gi.repository.Gio.OutputStream.write`. The content of the individual elements of ``vectors`` might be changed by this function. .. versionadded:: 2.60 :param vectors: the buffer containing the :obj:`~gi.repository.Gio.OutputVector` to write. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: writev_all_async(vectors: list[~gi.repository.Gio.OutputVector], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Request an asynchronous write of the bytes contained in the ``n_vectors`` ``vectors`` into the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.writev_all_finish` to get the result of the operation. This is the asynchronous version of :func:`~gi.repository.Gio.OutputStream.writev_all`. Call :func:`~gi.repository.Gio.OutputStream.writev_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 %G_PRIORITY_DEFAULT. Note that no copy of ``vectors`` will be made, so it must stay valid until ``callback`` is called. The content of the individual elements of ``vectors`` might be changed by this function. .. versionadded:: 2.60 :param vectors: the buffer containing the :obj:`~gi.repository.Gio.OutputVector` to write. :param io_priority: the I/O priority of the request :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: writev_all_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[bool, int] Finishes an asynchronous stream write operation started with :func:`~gi.repository.Gio.OutputStream.writev_all_async`. As a special exception to the normal conventions for functions that use :obj:`~gi.repository.GLib.Error`\, if this function returns :const:`False` (and sets ``error``\) then ``bytes_written`` will be set to the number of bytes that were successfully written 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 :func:`~gi.repository.Gio.OutputStream.writev_async`. .. versionadded:: 2.60 :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: writev_async(vectors: list[~gi.repository.Gio.OutputVector], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Request an asynchronous write of the bytes contained in ``n_vectors`` ``vectors`` into the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.writev_finish` to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. On success, the number of bytes written 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. on a partial I/O error, but generally we try to write as many bytes as requested. You are guaranteed that this method will never fail with :const:`~gi.repository.Gio.IOErrorEnum.WOULD_BLOCK` — if ``stream`` can't accept more data, the method will just wait until this changes. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_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. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.writev`. Note that no copy of ``vectors`` will be made, so it must stay valid until ``callback`` is called. .. versionadded:: 2.60 :param vectors: the buffer containing the :obj:`~gi.repository.Gio.OutputVector` to write. :param io_priority: the I/O priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: writev_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[bool, int] Finishes a stream writev operation. .. versionadded:: 2.60 :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. Virtual Methods --------------- .. rst-class:: interim-class .. class:: OutputStream :no-index: .. method:: do_close_async(io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.close_finish` to get the result of the operation. For behaviour details see :func:`~gi.repository.Gio.OutputStream.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. :param io_priority: the io priority of the request. :param cancellable: optional cancellable object :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_close_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Closes an output stream. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_close_fn(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool The type of the None singleton. :param cancellable: .. method:: do_flush(cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool 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 :const:`None`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error :const:`~gi.repository.Gio.IOErrorEnum.CANCELLED` will be returned. :param cancellable: optional cancellable object .. method:: do_flush_async(io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Forces an asynchronous write of all user-space buffered data for the given ``stream``\. For behaviour details see :func:`~gi.repository.Gio.OutputStream.flush`. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.flush_finish` to get the result of the operation. :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_flush_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes flushing an output stream. :param result: a GAsyncResult. .. method:: do_splice(source: ~gi.repository.Gio.InputStream, flags: ~gi.repository.Gio.OutputStreamSpliceFlags, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int Splices an input stream into an output stream. :param source: a :obj:`~gi.repository.Gio.InputStream`\. :param flags: a set of :obj:`~gi.repository.Gio.OutputStreamSpliceFlags`\. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: do_splice_async(source: ~gi.repository.Gio.InputStream, flags: ~gi.repository.Gio.OutputStreamSpliceFlags, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Splices a stream asynchronously. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.splice_finish` to get the result of the operation. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.splice`. :param source: a :obj:`~gi.repository.Gio.InputStream`\. :param flags: a set of :obj:`~gi.repository.Gio.OutputStreamSpliceFlags`\. :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_splice_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes an asynchronous stream splice operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_write_async(buffer: list[int] | None, io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Request an asynchronous write of ``count`` bytes from ``buffer`` into the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.write_finish` to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. A value of ``count`` larger than %G_MAXSSIZE will cause a :const:`~gi.repository.Gio.IOErrorEnum.INVALID_ARGUMENT` error. On success, the number of bytes written 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. on a partial I/O error, but generally we try to write as many bytes as requested. You are guaranteed that this method will never fail with :const:`~gi.repository.Gio.IOErrorEnum.WOULD_BLOCK` - if ``stream`` can't accept more data, the method will just wait until this changes. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_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. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.write`. Note that no copy of ``buffer`` will be made, so it must stay valid until ``callback`` is called. See :func:`~gi.repository.Gio.OutputStream.write_bytes_async` for a :obj:`~gi.repository.GLib.Bytes` version that will automatically hold a reference to the contents (without copying) for the duration of the call. :param buffer: the buffer containing the data to write. :param io_priority: the io priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_write_finish(result: ~gi.repository.Gio.AsyncResult) -> int Finishes a stream write operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_write_fn(buffer: list[int] | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> int The type of the None singleton. :param buffer: the buffer containing the data to write. :param cancellable: optional cancellable object .. method:: do_writev_async(vectors: list[~gi.repository.Gio.OutputVector], io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Request an asynchronous write of the bytes contained in ``n_vectors`` ``vectors`` into the stream. When the operation is finished ``callback`` will be called. You can then call :func:`~gi.repository.Gio.OutputStream.writev_finish` to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in :const:`~gi.repository.Gio.IOErrorEnum.PENDING` errors. On success, the number of bytes written 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. on a partial I/O error, but generally we try to write as many bytes as requested. You are guaranteed that this method will never fail with :const:`~gi.repository.Gio.IOErrorEnum.WOULD_BLOCK` — if ``stream`` can't accept more data, the method will just wait until this changes. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is %G_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. For the synchronous, blocking version of this function, see :func:`~gi.repository.Gio.OutputStream.writev`. Note that no copy of ``vectors`` will be made, so it must stay valid until ``callback`` is called. .. versionadded:: 2.60 :param vectors: the buffer containing the :obj:`~gi.repository.Gio.OutputVector` to write. :param io_priority: the I/O priority of the request. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_writev_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[bool, int] Finishes a stream writev operation. .. versionadded:: 2.60 :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: do_writev_fn(vectors: list[~gi.repository.Gio.OutputVector], cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~typing.Tuple[bool, int] The type of the None singleton. .. versionadded:: 2.60 :param vectors: the buffer containing the :obj:`~gi.repository.Gio.OutputVector` to write. :param cancellable: optional cancellable object Fields ------ .. rst-class:: interim-class .. class:: OutputStream :no-index: .. attribute:: parent_instance .. attribute:: priv