Skip to content

Gio.FileIOStream

class — extends IOStream, Seekable

GFileIOStream provides I/O streams that both read and write to the same file handle.

GFileIOStream implements Seekable, which allows the I/O stream to jump to arbitrary positions in the file and to truncate the file, provided the filesystem of the file supports these operations.

To find the position of a file I/O stream, use Seekable.tell.

To find out if a file I/O stream supports seeking, use Seekable.can_seek. To position a file I/O stream, use Seekable.seek. To find out if a file I/O stream supports truncating, use Seekable.can_truncate. To truncate a file I/O stream, use Seekable.truncate.

The default implementation of all the GFileIOStream operations and the implementation of Seekable just call into the same operations on the output stream.

Methods

get_etag

def get_etag(self) -> str | None

Gets the entity tag for the file when it has been written. This must be called after the stream has been written and closed, as the etag can change while writing.

query_info

def query_info(self, attributes: str, cancellable: Cancellable | None = ...) -> FileInfo

Queries a file io stream for the given attributes. This function blocks while querying the stream. For the asynchronous version of this function, see FileIOStream.query_info_async. While the stream is blocked, the stream will set the pending flag internally, and any other operations on the stream will fail with IOErrorEnum.PENDING.

Can fail if the stream was already closed (with error being set to IOErrorEnum.CLOSED), the stream has pending operations (with error being set to IOErrorEnum.PENDING), or if querying info is not supported for the stream's interface (with error being set to IOErrorEnum.NOT_SUPPORTED). I all cases of failure, None will be returned.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be set, and None will be returned.

Parameters:

  • attributes — a file attribute query string.
  • cancellable — optional Cancellable object, None to ignore.

query_info_async

def query_info_async(self, attributes: str, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[FileIOStream | None, AsyncResult], None] | None = ...) -> None

Asynchronously queries the stream for a FileInfo. When completed, callback will be called with a AsyncResult which can be used to finish the operation with FileIOStream.query_info_finish.

For the synchronous version of this function, see FileIOStream.query_info.

Parameters:

  • attributes — a file attribute query string.
  • io_priority — the I/O priority of the request
  • cancellable — optional Cancellable object, None to ignore.
  • callback — a GAsyncReadyCallback to call when the request is satisfied

query_info_finish

def query_info_finish(self, result: AsyncResult) -> FileInfo

Finalizes the asynchronous query started by FileIOStream.query_info_async.

Parameters:

Virtual methods

do_can_seek

def do_can_seek(self) -> bool

do_can_truncate

def do_can_truncate(self) -> bool

do_get_etag

def do_get_etag(self) -> str | None

Gets the entity tag for the file when it has been written. This must be called after the stream has been written and closed, as the etag can change while writing.

do_query_info

def do_query_info(self, attributes: str, cancellable: Cancellable | None = ...) -> FileInfo

Queries a file io stream for the given attributes. This function blocks while querying the stream. For the asynchronous version of this function, see FileIOStream.query_info_async. While the stream is blocked, the stream will set the pending flag internally, and any other operations on the stream will fail with IOErrorEnum.PENDING.

Can fail if the stream was already closed (with error being set to IOErrorEnum.CLOSED), the stream has pending operations (with error being set to IOErrorEnum.PENDING), or if querying info is not supported for the stream's interface (with error being set to IOErrorEnum.NOT_SUPPORTED). I all cases of failure, None will be returned.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum.CANCELLED will be set, and None will be returned.

Parameters:

  • attributes — a file attribute query string.
  • cancellable — optional Cancellable object, None to ignore.

do_query_info_async

def do_query_info_async(self, attributes: str, io_priority: int, cancellable: Cancellable | None = ..., callback: Callable[[FileIOStream | None, AsyncResult], None] | None = ...) -> None

Asynchronously queries the stream for a FileInfo. When completed, callback will be called with a AsyncResult which can be used to finish the operation with FileIOStream.query_info_finish.

For the synchronous version of this function, see FileIOStream.query_info.

Parameters:

  • attributes — a file attribute query string.
  • io_priority — the I/O priority of the request
  • cancellable — optional Cancellable object, None to ignore.
  • callback — a GAsyncReadyCallback to call when the request is satisfied

do_query_info_finish

def do_query_info_finish(self, result: AsyncResult) -> FileInfo

Finalizes the asynchronous query started by FileIOStream.query_info_async.

Parameters:

do_seek

def do_seek(self, offset: int, type: GLib.SeekType | int, cancellable: Cancellable | None = ...) -> bool

do_tell

def do_tell(self) -> int

do_truncate_fn

def do_truncate_fn(self, size: int, cancellable: Cancellable | None = ...) -> bool