path-text-utf8-0.0.1.6: Read and write UTF-8 text files

Safe HaskellNone
LanguageHaskell2010

Path.Text.UTF8

Contents

Description

Read and write UTF-8 text files.

Synopsis

Reading

readFile :: Path base File -> IO Text Source #

Read the contents of a UTF-8 encoded text file.

May throw IOError or UnicodeException. To handle these errors in Either instead, use tryReadFile.

tryReadFile :: Path base File -> IO (Either ReadError Text) Source #

Read the contents of a UTF-8 encoded text file.

Any IOError or UnicodeException that occurs is caught and returned as a ReadError on the Left side of the Either. To throw these exceptions instead, use readFile.

Writing

writeFile :: Path base File -> Text -> IO () Source #

Write text to a file in a UTF-8 encoding.

May throw IOError. To handle this error in Either instead, use tryWriteFile.

tryWriteFile :: Path base File -> Text -> IO (Either WriteError ()) Source #

Write text to a file in a UTF-8 encoding.

Any IOError that occurs is caught and returned on the Left side of the Either. To throw the exception instead, use writeFile.

Re-exports

type IOError = IOException #

The Haskell 2010 type for exceptions in the IO monad. Any I/O operation may raise an IOException instead of returning a result. For a more general type of exception, including also those that arise in pure code, see Exception.

In Haskell 2010, this is an opaque type.

data UnicodeException #

An exception type for representing Unicode encoding errors.

Constructors

DecodeError String (Maybe Word8)

Could not decode a byte sequence because it was invalid under the given encoding, or ran out of input in mid-decode.

parseAbsFile :: MonadThrow m => FilePath -> m (Path Abs File) #

Convert an absolute FilePath to a normalized absolute file Path.

Throws: InvalidAbsFile when the supplied path:

  • is not an absolute path
  • is a directory path i.e.

    • has a trailing path separator
    • is . or ends in /.
  • contains a .. path component representing the parent directory
  • is not a valid path (See isValid)

parseRelFile :: MonadThrow m => FilePath -> m (Path Rel File) #

Convert a relative FilePath to a normalized relative file Path.

Throws: InvalidRelFile when the supplied path:

  • is not a relative path
  • is ""
  • is a directory path i.e.

    • has a trailing path separator
    • is . or ends in /.
  • contains a .. path component representing the parent directory
  • is not a valid path (See isValid)