:right-sidebar: True Seekable =================================================================== .. currentmodule:: gi.repository.Gio .. class:: Seekable(*args, **kwargs) :no-contents-entry: Implementations: :class:`~gi.repository.Gio.BufferedInputStream`, :class:`~gi.repository.Gio.BufferedOutputStream`, :class:`~gi.repository.Gio.DataInputStream`, :class:`~gi.repository.Gio.DataOutputStream`, :class:`~gi.repository.Gio.FileIOStream`, :class:`~gi.repository.Gio.FileInputStream`, :class:`~gi.repository.Gio.FileOutputStream`, :class:`~gi.repository.Gio.MemoryInputStream`, :class:`~gi.repository.Gio.MemoryOutputStream` ``GSeekable`` is implemented by streams (implementations of :obj:`~gi.repository.Gio.InputStream` or :obj:`~gi.repository.Gio.OutputStream`\) that support seeking. Seekable streams largely fall into two categories: resizable and fixed-size. ``GSeekable`` on fixed-sized streams is approximately the same as POSIX ```lseek()`` `__ on a block device (for example: attempting to seek past the end of the device is an error). Fixed streams typically cannot be truncated. ``GSeekable`` on resizable streams is approximately the same as POSIX ```lseek()`` `__ on a normal file. Seeking past the end and writing data will usually cause the stream to resize by introducing zero bytes. Methods ------- .. rst-class:: interim-class .. class:: Seekable :no-index: .. method:: can_seek() -> bool Tests if the stream supports the ``GSeekableIface``. .. method:: can_truncate() -> bool Tests if the length of the stream can be adjusted with :func:`~gi.repository.Gio.Seekable.truncate`. .. method:: seek(offset: int, type: ~gi.repository.GLib.SeekType, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Seeks in the stream by the given ``offset``\, modified by ``type``\. Attempting to seek past the end of the stream will have different results depending on if the stream is fixed-sized or resizable. If the stream is resizable then seeking past the end and then writing will result in zeros filling the empty space. Seeking past the end of a resizable stream and reading will result in EOF. Seeking past the end of a fixed-sized stream will fail. Any operation that would result in a negative offset will fail. 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 offset: a :obj:`~gi.repository.gint64`\. :param type: a :obj:`~gi.repository.GLib.SeekType`\. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: tell() -> int Tells the current position within the stream. .. method:: truncate(offset: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Sets the length of the stream to ``offset``\. If the stream was previously larger than ``offset``\, the extra data is discarded. If the stream was previously shorter than ``offset``\, it is extended with NUL ('\0') bytes. 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. :param offset: new length for ``seekable``\, in bytes. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. Virtual Methods --------------- .. rst-class:: interim-class .. class:: Seekable :no-index: .. method:: do_can_seek() -> bool Tests if the stream supports the ``GSeekableIface``. .. method:: do_can_truncate() -> bool Tests if the length of the stream can be adjusted with :func:`~gi.repository.Gio.Seekable.truncate`. .. method:: do_seek(offset: int, type: ~gi.repository.GLib.SeekType, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Seeks in the stream by the given ``offset``\, modified by ``type``\. Attempting to seek past the end of the stream will have different results depending on if the stream is fixed-sized or resizable. If the stream is resizable then seeking past the end and then writing will result in zeros filling the empty space. Seeking past the end of a resizable stream and reading will result in EOF. Seeking past the end of a fixed-sized stream will fail. Any operation that would result in a negative offset will fail. 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 offset: a :obj:`~gi.repository.gint64`\. :param type: a :obj:`~gi.repository.GLib.SeekType`\. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. .. method:: do_tell() -> int Tells the current position within the stream. .. method:: do_truncate_fn(offset: int, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool The type of the None singleton. :param offset: new length for ``seekable``\, in bytes. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore.