gi-glib-2.0.24: GLib bindings

Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.GLib.Structs.MappedFile

Contents

- Exported types
- Methods
  - Overloaded methods
  - free
  - getBytes
  - getContents
  - getLength
  - new
  - newFromFd
  - ref
  - unref

Description

The `MappedFile` represents a file mapping created with `mappedFileNew`. It has only private members and should not be accessed directly.

Synopsis

- newtype MappedFile = MappedFile (ManagedPtr MappedFile)
- mappedFileFree :: (HasCallStack, MonadIO m) => MappedFile -> m ()
- mappedFileGetBytes :: (HasCallStack, MonadIO m) => MappedFile -> m Bytes
- mappedFileGetContents :: (HasCallStack, MonadIO m) => MappedFile -> m Text
- mappedFileGetLength :: (HasCallStack, MonadIO m) => MappedFile -> m Word64
- mappedFileNew :: (HasCallStack, MonadIO m) => [Char] -> Bool -> m MappedFile
- mappedFileNewFromFd :: (HasCallStack, MonadIO m) => Int32 -> Bool -> m MappedFile
- mappedFileRef :: (HasCallStack, MonadIO m) => MappedFile -> m MappedFile
- mappedFileUnref :: (HasCallStack, MonadIO m) => MappedFile -> m ()

# Exported types

newtype MappedFile Source #

Memory-managed wrapper type.

Constructors

MappedFile (ManagedPtr MappedFile) |

#### Instances

Instances details

Eq MappedFile Source # |
Instance details Defined in GI.GLib.Structs.MappedFile Methods (==) :: MappedFile -> MappedFile -> Bool # (/=) :: MappedFile -> MappedFile -> Bool #
IsGValue MappedFile Source # | Convert `MappedFile` to and from `GValue` with `toGValue` and `fromGValue`.
Instance details Defined in GI.GLib.Structs.MappedFile Methods toGValue :: MappedFile -> IO GValue Source # fromGValue :: GValue -> IO MappedFile Source #
ManagedPtrNewtype MappedFile Source # |
Instance details Defined in GI.GLib.Structs.MappedFile Methods toManagedPtr :: MappedFile -> ManagedPtr MappedFile Source #
TypedObject MappedFile Source # |
Instance details Defined in GI.GLib.Structs.MappedFile Methods glibType :: IO GType Source #
GBoxed MappedFile Source # |
Instance details Defined in GI.GLib.Structs.MappedFile
HasParentTypes MappedFile Source # |
Instance details Defined in GI.GLib.Structs.MappedFile
type ParentTypes MappedFile Source # |
Instance details Defined in GI.GLib.Structs.MappedFile type ParentTypes MappedFile = '[] :: [Type]

# Methods

## Overloaded methods

## free

mappedFileFree Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> MappedFile | `file`: a `MappedFile`
-> m () |

Deprecated: (Since version 2.22)Use `mappedFileUnref` instead.

This call existed before `MappedFile` had refcounting and is currently exactly the same as `mappedFileUnref`.

Since: 2.8

## getBytes

mappedFileGetBytes Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> MappedFile | `file`: a `MappedFile`
-> m Bytes | Returns: A newly allocated `Bytes` referencing data from `file`

Creates a new `Bytes` which references the data mapped from `file`. The mapped contents of the file must not be modified after creating this bytes object, because a `Bytes` should be immutable.

Since: 2.34

## getContents

mappedFileGetContents Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> MappedFile | `file`: a `MappedFile`
-> m Text | Returns: the contents of `file`, or `Nothing`.

Returns the contents of a `MappedFile`.

Note that the contents may not be zero-terminated, even if the `MappedFile` is backed by a text file.

If the file is empty then `Nothing` is returned.

Since: 2.8

## getLength

mappedFileGetLength Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> MappedFile | `file`: a `MappedFile`
-> m Word64 | Returns: the length of the contents of `file`.

Returns the length of the contents of a `MappedFile`.

Since: 2.8

## new

mappedFileNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> [Char] | `filename`: The path of the file to load, in the GLib filename encoding
-> Bool | `writable`: whether the mapping should be writable
-> m MappedFile | Returns: a newly allocated `MappedFile` which must be unref'd with `mappedFileUnref`, or `Nothing` if the mapping failed. (Can throw `GError`)

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 `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 `fileSetContents`).

If `filename` is the name of an empty, regular file, the function will successfully return an empty `MappedFile`. In other cases of size 0 (e.g. device files such as /dev/null), `error` will be set to the `FileError` value `G_FILE_ERROR_INVAL`.

Since: 2.8

## newFromFd

mappedFileNewFromFd Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Int32 | `fd`: The file descriptor of the file to load
-> Bool | `writable`: whether the mapping should be writable
-> m MappedFile | Returns: a newly allocated `MappedFile` which must be unref'd with `mappedFileUnref`, or `Nothing` if the mapping failed. (Can throw `GError`)

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 `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 `fileSetContents`).

Since: 2.32

## ref

mappedFileRef Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> MappedFile | `file`: a `MappedFile`
-> m MappedFile | Returns: the passed in `MappedFile`.

Increments the reference count of `file` by one. It is safe to call this function from any thread.

Since: 2.22

## unref

mappedFileUnref Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> MappedFile | `file`: a `MappedFile`
-> m () |

Decrements the reference count of `file` by one. If the reference count drops to 0, unmaps the buffer of `file` and frees it.

It is safe to call this function from any thread.

Since 2.22