-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Memory mapped files for POSIX and Windows
--   
--   This library provides a wrapper to mmap(2) or MapViewOfFile, allowing
--   files or devices to be lazily loaded into memory as strict or lazy
--   ByteStrings, ForeignPtrs or plain Ptrs, using the virtual memory
--   subsystem to do on-demand loading. Modifications are also supported.
@package mmap
@version 0.5.9

-- | This library provides a wrapper to mmap(2) or MapViewOfFile, allowing
--   files or devices to be lazily loaded into memory as strict or lazy
--   ByteStrings, ForeignPtrs or plain Ptrs, using the virtual memory
--   subsystem to do on-demand loading. Modifications are also supported.
module System.IO.MMap

-- | Mode of mapping. Four cases are supported.
data Mode

-- | file is mapped read-only, file must exist
ReadOnly :: Mode

-- | file is mapped read-write, file must exist
ReadWrite :: Mode

-- | file is mapped read-write, but changes aren't propagated to disk, file
--   must exist
WriteCopy :: Mode

-- | file is mapped read-write, if file does not exist it will be created
--   with default permissions, region parameter specifies size, if file
--   size is lower it will be extended with zeros
ReadWriteEx :: Mode

-- | The mmapFilePtr function maps a file or device into memory,
--   returning a tuple (ptr,rawsize,offset,size) where:
--   
--   
--   
- ptr is pointer to mmapped region
--   
- rawsize is length (in bytes) of mapped data, rawsize
--   might be greater than size because of alignment
--   
- offset tell where your data lives: plusPtr ptr
--   offset
--   
- size your data length (in bytes)
--   
--   
--   If mmapFilePtr fails for some reason, a throwErrno is
--   used.
--   
--   Use munmapFilePtr ptr rawsize to unmap memory.
--   
--   Memory mapped files will behave as if they were read lazily pages from
--   the file will be loaded into memory on demand.
mmapFilePtr :: FilePath -> Mode -> Maybe (Int64, Int) -> IO (Ptr a, Int, Int, Int)

-- | Memory map region of file using autounmap semantics. See
--   mmapFilePtr for description of parameters. The action
--   will be executed with tuple (ptr,size) as single argument.
--   This is the pointer to mapped data already adjusted and size of
--   requested region. Return value is that of action.
mmapWithFilePtr :: FilePath -> Mode -> Maybe (Int64, Int) -> ((Ptr (), Int) -> IO a) -> IO a

-- | Maps region of file and returns it as ForeignPtr. See
--   mmapFilePtr for details.
mmapFileForeignPtr :: FilePath -> Mode -> Maybe (Int64, Int) -> IO (ForeignPtr a, Int, Int)

-- | Maps region of file and returns it as ByteString. File is
--   mapped in in ReadOnly mode. See mmapFilePtr for details.
mmapFileByteString :: FilePath -> Maybe (Int64, Int) -> IO ByteString

-- | Unmaps memory region. As parameters use values marked as ptr and
--   rawsize in description of mmapFilePtr.
munmapFilePtr :: Ptr a -> Int -> IO ()

-- | The mmapFileForeignPtrLazy function maps a file or device into
--   memory, returning a list of tuples with the same meaning as in
--   function mmapFileForeignPtr.
--   
--   Chunks are really mapped into memory at the first inspection of a
--   chunk. They are kept in memory while they are referenced, garbage
--   collector takes care of the later.
mmapFileForeignPtrLazy :: FilePath -> Mode -> Maybe (Int64, Int64) -> IO [(ForeignPtr a, Int, Int)]

-- | Maps region of file and returns it as ByteString. File is
--   mapped in in ReadOnly mode. See mmapFileForeignPtrLazy
--   for details.
mmapFileByteStringLazy :: FilePath -> Maybe (Int64, Int64) -> IO ByteString
instance GHC.Internal.Enum.Enum System.IO.MMap.Mode
instance GHC.Classes.Eq System.IO.MMap.Mode
instance GHC.Classes.Ord System.IO.MMap.Mode
instance GHC.Internal.Read.Read System.IO.MMap.Mode
instance GHC.Internal.Show.Show System.IO.MMap.Mode
