Safe Haskell | None |
---|---|
Language | Haskell2010 |
Read and write UTF-8 text files.
Synopsis
- 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 #
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.
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. |
Instances
Eq UnicodeException | |
Defined in Data.Text.Encoding.Error (==) :: UnicodeException -> UnicodeException -> Bool # (/=) :: UnicodeException -> UnicodeException -> Bool # | |
Show UnicodeException | |
Defined in Data.Text.Encoding.Error showsPrec :: Int -> UnicodeException -> ShowS # show :: UnicodeException -> String # showList :: [UnicodeException] -> ShowS # | |
Exception UnicodeException | |
Defined in Data.Text.Encoding.Error | |
NFData UnicodeException | |
Defined in Data.Text.Encoding.Error rnf :: UnicodeException -> () # |
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
)