system-fileio-0.2.5: Consistent filesystem interaction across GHC versions

Portabilityportable
Maintainerjmillikin@gmail.com
Safe HaskellSafe-Infered

System.File

Contents

Description

Deprecated alias for Filesystem.

Synopsis

Documentation

data Handle

Haskell defines operations to read and write characters from and to files, represented by values of type Handle. Each value of this type is a handle: a record used by the Haskell run-time system to manage I/O with file system objects. A handle has at least the following properties:

  • whether it manages input or output or both;
  • whether it is open, closed or semi-closed;
  • whether the object is seekable;
  • whether buffering is disabled, or enabled on a line or block basis;
  • a buffer (whose length may be zero).

Most handles will also have a current I/O position indicating where the next input or output operation will occur. A handle is readable if it manages only input or both input and output; likewise, it is writable if it manages only output or both input and output. A handle is open when first allocated. Once it is closed it can no longer be used for either input or output, though an implementation cannot re-use its storage while references remain to it. Handles are in the Show and Eq classes. The string produced by showing a handle is system dependent; it should include enough information to identify the handle for debugging. A handle is equal according to == only to itself; no attempt is made to compare the internal state of different handles for equality.

File operations

copyFileSource

Arguments

:: FilePath

Old location

-> FilePath

New location

-> IO () 

Copy the content and permissions of a file to a new entry in the filesystem. If a file already exists at the new location, it will be replaced. Copying a file is not atomic.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

Since: 0.1.1

File information

getModified :: FilePath -> IO UTCTimeSource

Get when the object at a given path was last modified.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

Since: 0.2

getSize :: FilePath -> IO IntegerSource

Get the size of an object at a given path. For special objects like links or directories, the size is filesystem‐ and platform‐dependent.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

Since: 0.2

Binary files

openFile :: FilePath -> IOMode -> IO HandleSource

Open a file in binary mode, and return an open Handle. The Handle should be closed with hClose when it is no longer needed.

withFile is easier to use, because it will handle the Handle’s lifetime automatically.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

withFile :: FilePath -> IOMode -> (Handle -> IO a) -> IO aSource

Open a file in binary mode, and pass its Handle to a provided computation. The Handle will be automatically closed when the computation returns.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

readFile :: FilePath -> IO ByteStringSource

Read in the entire content of a binary file.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

writeFile :: FilePath -> ByteString -> IO ()Source

Replace the entire content of a binary file with the provided ByteString.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

appendFile :: FilePath -> ByteString -> IO ()Source

Append a ByteString to a file. If the file does not exist, it will be created.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

Text files

openTextFile :: FilePath -> IOMode -> IO HandleSource

Open a file in text mode, and return an open Handle. The Handle should be closed with hClose when it is no longer needed.

withTextFile is easier to use, because it will handle the Handle’s lifetime automatically.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

withTextFile :: FilePath -> IOMode -> (Handle -> IO a) -> IO aSource

Open a file in text mode, and pass its Handle to a provided computation. The Handle will be automatically closed when the computation returns.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

readTextFile :: FilePath -> IO TextSource

Read in the entire content of a text file.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

writeTextFile :: FilePath -> Text -> IO ()Source

Replace the entire content of a text file with the provided Text.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.

appendTextFile :: FilePath -> Text -> IO ()Source

Append Text to a file. If the file does not exist, it will be created.

This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.