GLib.MappedFile¶
Fields¶
None
Methods¶
| class | new(filename, writable) | 
| class | new_from_fd(fd, writable) | 
| free() | |
| get_bytes() | |
| get_contents() | |
| get_length() | |
| ref() | |
| unref() | 
Details¶
- 
class GLib.MappedFile¶
- The - GLib.MappedFilerepresents a file mapping created with- GLib.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.MappedFilewhich must be unref’d with- GLib.MappedFile.unref(), or- Noneif 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. using- GLib.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 the- GLib.FileErrorvalue- GLib.FileError.INVAL.- New in version 2.8. 
 - 
classmethod new_from_fd(fd, writable)[source]¶
- Parameters: - Raises: - Returns: - a newly allocated - GLib.MappedFilewhich must be unref’d with- GLib.MappedFile.unref(), or- Noneif 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. using- GLib.file_set_contents()).- New in version 2.32. 
 - 
free()[source]¶
- This call existed before - GLib.MappedFilehad refcounting and is currently exactly the same as- GLib.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.Bytesreferencing data from self- Return type: - GLib.Bytes- Creates a new - GLib.Byteswhich references the data mapped from self. The mapped contents of the file must not be modified after creating this bytes object, because a- GLib.Bytesshould be immutable.- New in version 2.34. 
 - 
get_contents()[source]¶
- Returns: - the contents of self, or - None.- Return type: - str- Returns the contents of a - GLib.MappedFile.- Note that the contents may not be zero-terminated, even if the - GLib.MappedFileis backed by a text file.- If the file is empty then - Noneis returned.- New in version 2.8. 
 - 
get_length()[source]¶
- Returns: - the length of the contents of self. - Return type: - int- 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: - GLib.MappedFile- Increments the reference count of self by one. It is safe to call this function from any thread. - New in version 2.22. 
 
- 
classmethod