Safe Haskell | None |
---|---|
Language | Haskell2010 |
Read and write UTF-8 text files.
- readFile :: Path base File -> IO Text
- tryReadFile :: Path base File -> IO (Either ReadError Text)
- data ReadError
- writeFile :: Path base File -> Text -> IO ()
- tryWriteFile :: Path base File -> Text -> IO (Either WriteError ())
- type WriteError = IOError
- type IOError = IOException
- data UnicodeException :: * = DecodeError String (Maybe Word8)
- parseAbsFile :: MonadThrow m => FilePath -> m (Path Abs File)
- parseRelFile :: MonadThrow m => FilePath -> m (Path Rel File)
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
.
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 #
type WriteError = IOError Source #
Re-exports
type IOError = IOException #
data UnicodeException :: * #
An exception type for representing Unicode encoding errors.
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
)