FileSaver#
Superclasses: Object
Save a Buffer
into a file.
A GtkSourceFileSaver
object permits to save a Buffer
into a
File
.
A file saver should be used only for one save operation, including errors
handling. If an error occurs, you can reconfigure the saver and relaunch the
operation with save_async
.
Constructors#
- class FileSaver
- classmethod new(buffer: Buffer, file: File) FileSaver #
Creates a new
FileSaver
object. Thebuffer
will be saved to theFile
's location.This constructor is suitable for a simple “save” operation, when the
file
already contains a non-None
location
.
- classmethod new_with_target(buffer: Buffer, file: File, target_location: File) FileSaver #
Creates a new
FileSaver
object with a target location.When the file saving is finished successfully,
target_location
is set to thefile
'slocation
property. If an error occurs, the previous valid location is still available inFile
.This constructor is suitable for a “save as” operation, or for saving a new buffer for the first time.
Methods#
- class FileSaver
-
- get_compression_type() CompressionType #
- get_flags() FileSaverFlags #
- get_newline_type() NewlineType #
- save_async(io_priority: int, cancellable: Cancellable | None = None, progress_callback: Callable[[int, int, Any], None] | None = None, progress_callback_data: Any = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Saves asynchronously the buffer into the file.
See the
AsyncResult
documentation to know how to use this function.- Parameters:
io_priority – the I/O priority of the request. E.g. %G_PRIORITY_LOW, %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
cancellable – optional
Cancellable
object,None
to ignore.progress_callback – function to call back with progress information, or
None
if progress information is not needed.progress_callback_data – user data to pass to
progress_callback
.callback – a
AsyncReadyCallback
to call when the request is satisfied.user_data – user data to pass to
callback
.
- save_finish(result: AsyncResult) bool #
Finishes a file saving started with
save_async
.If the file has been saved successfully, the following
File
properties will be updated: the location, the encoding, the newline type and the compression type.Since the 3.20 version,
set_modified
is called withFalse
if the file has been saved successfully.- Parameters:
result – a
AsyncResult
.
- set_compression_type(compression_type: CompressionType) None #
Sets the compression type. By default the compression type is taken from the
File
.- Parameters:
compression_type – the new compression type.
- set_encoding(encoding: Encoding | None = None) None #
Sets the encoding. If
encoding
isNone
, the UTF-8 encoding will be set.By default the encoding is taken from the
File
.- Parameters:
encoding – the new encoding, or
None
for UTF-8.
- set_flags(flags: FileSaverFlags) None #
- Parameters:
flags – the new flags.
- set_newline_type(newline_type: NewlineType) None #
Sets the newline type. By default the newline type is taken from the
File
.- Parameters:
newline_type – the new newline type.
Properties#
- class FileSaver
-
- props.compression_type: CompressionType#
The type of the None singleton.
- props.flags: FileSaverFlags#
The type of the None singleton.
- props.newline_type: NewlineType#
The type of the None singleton.