LIO.TmpFile
Contents
Description
This module creates new files and directories with unique names. Its functionality is similary to C's mkstemp() and mkdtemp() functions.
- mkTmpFile :: IOMode -> FilePath -> String -> IO (Handle, FilePath)
- mkTmpDir :: FilePath -> String -> IO ((), FilePath)
- mkTmpDir' :: FilePath -> String -> IO FilePath
- mkTmp :: (FilePath -> IO a) -> FilePath -> String -> IO (a, FilePath)
- openFileExclusive :: IOMode -> FilePath -> IO Handle
- tmpName :: IO String
- nextTmpName :: String -> String
- serializele :: Int -> Integer -> [Word8]
- unserializele :: [Word8] -> Integer
- hSync :: Handle -> IO ()
The high level interface
Arguments
:: IOMode |
|
-> FilePath | Directory in which to create file |
-> String | Suffix for new file name |
-> IO (Handle, FilePath) | Returns open handle to new file, along with pathname of new file |
Creates a new file with a unique name in a particular directory
Arguments
:: FilePath | Directory in which to create subdirectory |
-> String | Suffix to append to new directory name |
-> IO FilePath | Returns full path to new directory |
Like mkTmpDir
, but just returns the pathname of the new directory.
Some lower-level helper functions
Arguments
:: (FilePath -> IO a) | The function to execute ( |
-> FilePath | Directory to prepend to temp file names |
-> String | Suffix for new file name |
-> IO (a, FilePath) | The result of |
Executes a function on temporary file names until the function
does not throw AlreadyExistsError. For example, mkTmpFile
is
defined as:
mkTmpFile m d s = mkTmp (openFileExclusive m) d s
openFileExclusive :: IOMode -> FilePath -> IO HandleSource
Opens a file in exclusive mode, throwing AlreadyExistsError if the file name is already in use.
Functions for generating unique names
Return a temorary file name, based on the value of the current time of day clock.
nextTmpName :: String -> StringSource
When the file name returned by tmpName
already exists,
nextTmpName
modifies the file name to generate a new one.
Serialize an Integer into an array of bytes, in little-endian order.
unserializele :: [Word8] -> IntegerSource
Take an array of bytes containing an Integer serialized in little-endian order, and return the Integer.