albertdahlin / elm-posix / Posix.IO.File

Common file IO


type alias Filename =
String

contentsOf : Filename -> IO (Result String String)

Read the contents of a file.

writeContentsTo : Filename -> String -> IO ()

Write contents to a file. The Program will fail if there is a problem.

stat : Filename -> IO (Result String Stats)

Read file stats


type alias Stats =
{ size : Basics.Int
, atime : Basics.Float
, mtime : Basics.Float
, ctime : Basics.Float 
}

File stats

Directory IO

readDir : String -> IO (Result String (List Entry))

Read the contents of a directory.


type Entry
    = File String
    | Directory String
    | Other String

Directory entry

mkDir : Basics.Bool -> String -> IO ()

Create a dir.

mkdir <recursive> <name>

Posix Stream IO


type FD ability

File Descriptor


type Flag a

open : Filename -> Flag a -> IO (Result String (FD a))

Open a file

flagRead : Flag (Readable (Seekable {}))

Open file for reading. (r)

An error occurs if the file does not exist. The stream is positioned at the beginning of the file.

flagReadPlus : Flag (Readable (Writable (Seekable {})))

Open file for reading and writing. (r+)

An exception occurs if the file does not exist. The stream is positioned at the beginning of the file.

flagWrite : Flag (Writable (Seekable {}))

Open file for writing. (w)

The file is created (if it does not exist) or truncated (if it exists). The stream is positioned at the beginning of the file.

flagWritePlus : Flag (Readable (Writable (Seekable {})))

Open file for reading and writing. (w+)

The file is created (if it does not exist) or truncated (if it exists). The stream is positioned at the beginning of the file.

flagAppend : Flag (Writable {})

Open file for appending (writing at the end of a file). (a)

The file is created if it does not exist. The stream is positioned at the end of the file.

flagAppendPlus : Flag (Readable (Writable {}))

Open file for reading and appending. (a+)

The file is created if it does not exist. The stream is positioned at the end of the file.

read : FD (Readable a) -> IO String

Read a file

write : FD (Writable a) -> String -> IO ()

Write to a file

Standard IO streams

stdErr : FD (Writable {})

Standard Error

stdIn : FD (Readable {})

Standard In

stdOut : FD (Writable {})

Standard Out