lio-eci11-0.1: Labeled IO library

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.

Synopsis

The high level interface

mkTmpFileSource

Arguments

:: IOMode

WriteMode, AppendMode, or ReadWriteMode (It is an error to use ReadMode.)

-> 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

mkTmpDirSource

Arguments

:: FilePath

Directory in which to create subdirectory

-> String

Suffix to append to new directory name

-> IO ((), FilePath)

Returns full path to new directory

Creates a new subdirectory with uniqe file name. Returns the pathname of the new directory as the second element of a pair, just for consistency with the interface to mkTmpFile. See mkTmpDir' if you don't want this behavior.

mkTmpDir'Source

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

mkTmpSource

Arguments

:: (FilePath -> IO a)

The function to execute (f)

-> FilePath

Directory to prepend to temp file names

-> String

Suffix for new file name

-> IO (a, FilePath)

The result of f and the FilePath on which it finally succeeded.

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

tmpName :: IO StringSource

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.

serializeleSource

Arguments

:: Int

Minimum number of bytes to return

-> Integer

The Integer to serialize

-> [Word8] 

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.

For flushing temp files before rename

hSync :: Handle -> IO ()Source

Flushes a Handle to disk with fsync()