OutputStream#
Superclasses: Object
Subclasses: FileOutputStream, FilterOutputStream, MemoryOutputStream, UnixOutputStream
GOutputStream is a base class for implementing streaming output.
It has functions to write to a stream (write),
to close a stream (close) and to flush pending
writes (flush).
To copy the content of an input stream to an output stream without
manually handling the reads and writes, use splice.
See the documentation for 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#
- class OutputStream
-
- close(cancellable: Cancellable | None = None) bool#
Closes the stream, releasing resources related to it.
Once the stream is closed, all other operations will return
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
CLOSEDfor 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
cancellableis notNone, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill 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.- Parameters:
cancellable – optional cancellable object
- async close_async(self, io_priority: int) bool#
This is the awaitable version of
close_async().- Parameters:
io_priority – the io priority of the request.
- close_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished
callbackwill be called. You can then callclose_finish()to get the result of the operation.For behaviour details see
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.
- Parameters:
io_priority – the io priority of the request.
cancellable – optional cancellable object
callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- close_finish(result: AsyncResult) bool#
Closes an output stream.
- Parameters:
result – a
AsyncResult.
- do_close_async(self, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
io_priority
cancellable
callback
user_data
- do_close_finish(self, result: AsyncResult) bool#
- Parameters:
result
- do_close_fn(self, cancellable: Cancellable | None = None) bool#
- Parameters:
cancellable
- do_flush(self, cancellable: Cancellable | None = None) bool#
- Parameters:
cancellable
- do_flush_async(self, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
io_priority
cancellable
callback
user_data
- do_flush_finish(self, result: AsyncResult) bool#
- Parameters:
result
- do_splice(self, source: InputStream, flags: OutputStreamSpliceFlags, cancellable: Cancellable | None = None) int#
- Parameters:
source
flags
cancellable
- do_splice_async(self, source: InputStream, flags: OutputStreamSpliceFlags, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
source
flags
io_priority
cancellable
callback
user_data
- do_splice_finish(self, result: AsyncResult) int#
- Parameters:
result
- do_write_async(self, buffer: list[int] | None, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
buffer
io_priority
cancellable
callback
user_data
- do_write_finish(self, result: AsyncResult) int#
- Parameters:
result
- do_write_fn(self, buffer: list[int] | None = None, cancellable: Cancellable | None = None) int#
- Parameters:
buffer
cancellable
- do_writev_async(self, vectors: list[OutputVector], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
vectors
io_priority
cancellable
callback
user_data
- do_writev_finish(self, result: AsyncResult) tuple[bool, int]#
- Parameters:
result
- do_writev_fn(self, vectors: list[OutputVector], cancellable: Cancellable | None = None) tuple[bool, int]#
- Parameters:
vectors
cancellable
- flush(cancellable: 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
cancellableis notNone, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill be returned.- Parameters:
cancellable – optional cancellable object
- async flush_async(self, io_priority: int) bool#
This is the awaitable version of
flush_async().- Parameters:
io_priority – the io priority of the request.
- flush_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Forces an asynchronous write of all user-space buffered data for the given
stream. For behaviour details seeflush().When the operation is finished
callbackwill be called. You can then callflush_finish()to get the result of the operation.- Parameters:
io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- flush_finish(result: AsyncResult) bool#
Finishes flushing an output stream.
- Parameters:
result – a GAsyncResult.
- 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.
Added in version 2.24.
- set_pending() bool#
Sets
streamto have actions pending. If the pending flag is already set orstreamis closed, it will returnFalseand seterror.
- splice(source: InputStream, flags: OutputStreamSpliceFlags, cancellable: Cancellable | None = None) int#
Splices an input stream into an output stream.
- Parameters:
source – a
InputStream.flags – a set of
OutputStreamSpliceFlags.cancellable – optional
Cancellableobject,Noneto ignore.
- async splice_async(self, source: InputStream, flags: OutputStreamSpliceFlags, io_priority: int) int#
This is the awaitable version of
splice_async().- Parameters:
source – a
InputStream.flags – a set of
OutputStreamSpliceFlags.io_priority – the io priority of the request.
- splice_async(source: InputStream, flags: OutputStreamSpliceFlags, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Splices a stream asynchronously. When the operation is finished
callbackwill be called. You can then callsplice_finish()to get the result of the operation.For the synchronous, blocking version of this function, see
splice().- Parameters:
source – a
InputStream.flags – a set of
OutputStreamSpliceFlags.io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- splice_finish(result: AsyncResult) int#
Finishes an asynchronous stream splice operation.
- Parameters:
result – a
AsyncResult.
- write(buffer: list[int], cancellable: Cancellable | None = None) int#
Tries to write
countbytes frombufferinto the stream. Will block during the operation.If count is 0, returns 0 and does nothing. A value of
countlarger than %G_MAXSSIZE will cause aINVALID_ARGUMENTerror.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
countis 0).If
cancellableis notNone, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill 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
erroris set accordingly.- Parameters:
buffer – the buffer containing the data to write.
cancellable – optional cancellable object
- write_all(buffer: list[int], cancellable: Cancellable | None = None) tuple[bool, int]#
Tries to write
countbytes frombufferinto the stream. Will block during the operation.This function is similar to
write(), except it tries to write as many bytes as requested, only stopping on an error.On a successful write of
countbytes,Trueis returned, andbytes_writtenis set tocount.If there is an error during the operation
Falseis returned anderroris set to indicate the error status.As a special exception to the normal conventions for functions that use
Error, if this function returnsFalse(and setserror) thenbytes_writtenwill 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 aroundwrite().- Parameters:
buffer – the buffer containing the data to write.
cancellable – optional
Cancellableobject,Noneto ignore.
- async write_all_async(self, buffer: list[int], io_priority: int) tuple[bool, int]#
This is the awaitable version of
write_all_async().Added in version 2.44.
- Parameters:
buffer – the buffer containing the data to write
io_priority – the io priority of the request
- write_all_async(buffer: list[int], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Request an asynchronous write of
countbytes frombufferinto the stream. When the operation is finishedcallbackwill be called. You can then callwrite_all_finish()to get the result of the operation.This is the asynchronous version of
write_all().Call
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
bufferwill be made, so it must stay valid untilcallbackis called.Added in version 2.44.
- Parameters:
buffer – the buffer containing the data to write
io_priority – the io priority of the request
cancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- write_all_finish(result: AsyncResult) tuple[bool, int]#
Finishes an asynchronous stream write operation started with
write_all_async().As a special exception to the normal conventions for functions that use
Error, if this function returnsFalse(and setserror) thenbytes_writtenwill 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 aroundwrite_async().Added in version 2.44.
- Parameters:
result – a
AsyncResult
- async write_async(self, buffer: list[int], io_priority: int) int#
This is the awaitable version of
write_async().- Parameters:
buffer – the buffer containing the data to write.
io_priority – the io priority of the request.
- write_async(buffer: list[int], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Request an asynchronous write of
countbytes frombufferinto the stream. When the operation is finishedcallbackwill be called. You can then callwrite_finish()to get the result of the operation.During an async request no other sync and async calls are allowed, and will result in
PENDINGerrors.A value of
countlarger than %G_MAXSSIZE will cause aINVALID_ARGUMENTerror.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
WOULD_BLOCK- ifstreamcan’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
write().Note that no copy of
bufferwill be made, so it must stay valid untilcallbackis called. Seewrite_bytes_async()for aBytesversion that will automatically hold a reference to the contents (without copying) for the duration of the call.- Parameters:
buffer – the buffer containing the data to write.
io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- write_bytes(bytes: Bytes, cancellable: Cancellable | None = None) int#
A wrapper function for
write()which takes aBytesas input. This can be more convenient for use by language bindings or in other cases where the refcounted nature ofBytesis helpful over a bare pointer interface.However, note that this function may still perform partial writes, just like
write(). If that occurs, to continue writing, you will need to create a newBytescontaining just the remaining bytes, usingnew_from_bytes(). Passing the sameBytesinstance multiple times potentially can result in duplicated data in the output stream.- Parameters:
bytes – the
Bytesto writecancellable – optional cancellable object
- async write_bytes_async(self, bytes: Bytes, io_priority: int) int#
This is the awaitable version of
write_bytes_async().- Parameters:
bytes – The bytes to write
io_priority – the io priority of the request.
- write_bytes_async(bytes: Bytes, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
This function is similar to
write_async(), but takes aBytesas input. Due to the refcounted nature ofBytes, this allows the stream to avoid taking a copy of the data.However, note that this function may still perform partial writes, just like
write_async(). If that occurs, to continue writing, you will need to create a newBytescontaining just the remaining bytes, usingnew_from_bytes(). Passing the sameBytesinstance multiple times potentially can result in duplicated data in the output stream.For the synchronous, blocking version of this function, see
write_bytes().- Parameters:
bytes – The bytes to write
io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- write_bytes_finish(result: AsyncResult) int#
Finishes a stream write-from-
Bytesoperation.- Parameters:
result – a
AsyncResult.
- write_finish(result: AsyncResult) int#
Finishes a stream write operation.
- Parameters:
result – a
AsyncResult.
- writev(vectors: list[OutputVector], cancellable: Cancellable | None = None) tuple[bool, int]#
Tries to write the bytes contained in the
n_vectorsvectorsinto the stream. Will block during the operation.If
n_vectorsis 0 or the sum of all bytes invectorsis 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_vectorsis 0 or the sum of all bytes invectorsis 0).If
cancellableis notNone, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill 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
writev()may have limitations on the aggregate buffer size, and will returnINVALID_ARGUMENTif these are exceeded. For example, when writing to a local file on UNIX platforms, the aggregate buffer size must not exceed %G_MAXSSIZE bytes.Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.cancellable – optional cancellable object
- writev_all(vectors: list[OutputVector], cancellable: Cancellable | None = None) tuple[bool, int]#
Tries to write the bytes contained in the
n_vectorsvectorsinto the stream. Will block during the operation.This function is similar to
writev(), except it tries to write as many bytes as requested, only stopping on an error.On a successful write of all
n_vectorsvectors,Trueis returned, andbytes_writtenis set to the sum of all the sizes ofvectors.If there is an error during the operation
Falseis returned anderroris set to indicate the error status.As a special exception to the normal conventions for functions that use
Error, if this function returnsFalse(and setserror) thenbytes_writtenwill 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 aroundwrite().The content of the individual elements of
vectorsmight be changed by this function.Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.cancellable – optional
Cancellableobject,Noneto ignore.
- async writev_all_async(self, vectors: list[OutputVector], io_priority: int) tuple[bool, int]#
This is the awaitable version of
writev_all_async().Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.io_priority – the I/O priority of the request
- writev_all_async(vectors: list[OutputVector], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Request an asynchronous write of the bytes contained in the
n_vectorsvectorsinto the stream. When the operation is finishedcallbackwill be called. You can then callwritev_all_finish()to get the result of the operation.This is the asynchronous version of
writev_all().Call
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
vectorswill be made, so it must stay valid untilcallbackis called. The content of the individual elements ofvectorsmight be changed by this function.Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.io_priority – the I/O priority of the request
cancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- writev_all_finish(result: AsyncResult) tuple[bool, int]#
Finishes an asynchronous stream write operation started with
writev_all_async().As a special exception to the normal conventions for functions that use
Error, if this function returnsFalse(and setserror) thenbytes_writtenwill 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 aroundwritev_async().Added in version 2.60.
- Parameters:
result – a
AsyncResult
- async writev_async(self, vectors: list[OutputVector], io_priority: int) tuple[bool, int]#
This is the awaitable version of
writev_async().Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.io_priority – the I/O priority of the request.
- writev_async(vectors: list[OutputVector], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Request an asynchronous write of the bytes contained in
n_vectorsvectorsinto the stream. When the operation is finishedcallbackwill be called. You can then callwritev_finish()to get the result of the operation.During an async request no other sync and async calls are allowed, and will result in
PENDINGerrors.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
WOULD_BLOCK— ifstreamcan’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
writev().Note that no copy of
vectorswill be made, so it must stay valid untilcallbackis called.Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.io_priority – the I/O priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- writev_finish(result: AsyncResult) tuple[bool, int]#
Finishes a stream writev operation.
Added in version 2.60.
- Parameters:
result – a
AsyncResult.
Virtual Methods#
- class OutputStream
- do_close_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished
callbackwill be called. You can then callclose_finish()to get the result of the operation.For behaviour details see
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.
- Parameters:
io_priority – the io priority of the request.
cancellable – optional cancellable object
callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- do_close_finish(result: AsyncResult) bool#
Closes an output stream.
- Parameters:
result – a
AsyncResult.
- do_close_fn(cancellable: Cancellable | None = None) bool#
The type of the None singleton.
- Parameters:
cancellable
- do_flush(cancellable: 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
cancellableis notNone, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLEDwill be returned.- Parameters:
cancellable – optional cancellable object
- do_flush_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Forces an asynchronous write of all user-space buffered data for the given
stream. For behaviour details seeflush().When the operation is finished
callbackwill be called. You can then callflush_finish()to get the result of the operation.- Parameters:
io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- do_flush_finish(result: AsyncResult) bool#
Finishes flushing an output stream.
- Parameters:
result – a GAsyncResult.
- do_splice(source: InputStream, flags: OutputStreamSpliceFlags, cancellable: Cancellable | None = None) int#
Splices an input stream into an output stream.
- Parameters:
source – a
InputStream.flags – a set of
OutputStreamSpliceFlags.cancellable – optional
Cancellableobject,Noneto ignore.
- do_splice_async(source: InputStream, flags: OutputStreamSpliceFlags, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Splices a stream asynchronously. When the operation is finished
callbackwill be called. You can then callsplice_finish()to get the result of the operation.For the synchronous, blocking version of this function, see
splice().- Parameters:
source – a
InputStream.flags – a set of
OutputStreamSpliceFlags.io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- do_splice_finish(result: AsyncResult) int#
Finishes an asynchronous stream splice operation.
- Parameters:
result – a
AsyncResult.
- do_write_async(buffer: list[int] | None, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Request an asynchronous write of
countbytes frombufferinto the stream. When the operation is finishedcallbackwill be called. You can then callwrite_finish()to get the result of the operation.During an async request no other sync and async calls are allowed, and will result in
PENDINGerrors.A value of
countlarger than %G_MAXSSIZE will cause aINVALID_ARGUMENTerror.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
WOULD_BLOCK- ifstreamcan’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
write().Note that no copy of
bufferwill be made, so it must stay valid untilcallbackis called. Seewrite_bytes_async()for aBytesversion that will automatically hold a reference to the contents (without copying) for the duration of the call.- Parameters:
buffer – the buffer containing the data to write.
io_priority – the io priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- do_write_finish(result: AsyncResult) int#
Finishes a stream write operation.
- Parameters:
result – a
AsyncResult.
- do_write_fn(buffer: list[int] | None = None, cancellable: Cancellable | None = None) int#
The type of the None singleton.
- Parameters:
buffer – the buffer containing the data to write.
cancellable – optional cancellable object
- do_writev_async(vectors: list[OutputVector], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Request an asynchronous write of the bytes contained in
n_vectorsvectorsinto the stream. When the operation is finishedcallbackwill be called. You can then callwritev_finish()to get the result of the operation.During an async request no other sync and async calls are allowed, and will result in
PENDINGerrors.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
WOULD_BLOCK— ifstreamcan’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
writev().Note that no copy of
vectorswill be made, so it must stay valid untilcallbackis called.Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.io_priority – the I/O priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.callback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to callback function
- do_writev_finish(result: AsyncResult) tuple[bool, int]#
Finishes a stream writev operation.
Added in version 2.60.
- Parameters:
result – a
AsyncResult.
- do_writev_fn(vectors: list[OutputVector], cancellable: Cancellable | None = None) tuple[bool, int]#
The type of the None singleton.
Added in version 2.60.
- Parameters:
vectors – the buffer containing the
OutputVectorto write.cancellable – optional cancellable object