GLib.MappedFile¶
Fields¶
None
Methods¶
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class GLib.MappedFile¶
The
GLib.MappedFile
represents a file mapping created withGLib.MappedFile.new
(). It has only private members and should not be accessed directly.- classmethod new(filename, writable)[source]¶
- Parameters:
- Raises:
- Returns:
a newly allocated
GLib.MappedFile
which must be unref’d withGLib.MappedFile.unref
(), orNone
if the mapping failed.- Return type:
Maps a file into memory. On UNIX, this is using the mmap() function.
If writable is
True
, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.Note that modifications of the underlying file might affect the contents of the
GLib.MappedFile
. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. usingGLib.file_set_contents
()).If filename is the name of an empty, regular file, the function will successfully return an empty
GLib.MappedFile
. In other cases of size 0 (e.g. device files such as /dev/null), error will be set to theGLib.FileError
valueGLib.FileError.INVAL
.New in version 2.8.
- classmethod new_from_fd(fd, writable)[source]¶
- Parameters:
- Raises:
- Returns:
a newly allocated
GLib.MappedFile
which must be unref’d withGLib.MappedFile.unref
(), orNone
if the mapping failed.- Return type:
Maps a file into memory. On UNIX, this is using the mmap() function.
If writable is
True
, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.Note that modifications of the underlying file might affect the contents of the
GLib.MappedFile
. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. usingGLib.file_set_contents
()).New in version 2.32.
- free()[source]¶
This call existed before
GLib.MappedFile
had refcounting and is currently exactly the same asGLib.MappedFile.unref
().New in version 2.8.
Deprecated since version 2.22: Use
GLib.MappedFile.unref
() instead.
- get_bytes()[source]¶
- Returns:
A newly allocated
GLib.Bytes
referencing data from self- Return type:
Creates a new
GLib.Bytes
which references the data mapped from self. The mapped contents of the file must not be modified after creating this bytes object, because aGLib.Bytes
should be immutable.New in version 2.34.
- get_contents()[source]¶
-
Returns the contents of a
GLib.MappedFile
.Note that the contents may not be zero-terminated, even if the
GLib.MappedFile
is backed by a text file.If the file is empty then
None
is returned.New in version 2.8.
- get_length()[source]¶
- Returns:
the length of the contents of self.
- Return type:
Returns the length of the contents of a
GLib.MappedFile
.New in version 2.8.
- ref()[source]¶
- Returns:
the passed in
GLib.MappedFile
.- Return type:
Increments the reference count of self by one. It is safe to call this function from any thread.
New in version 2.22.