Copyright | (c) 2009 2010 Bryan O'Sullivan (c) 2009 Simon Marlow |
---|---|
License | BSD-style |
Maintainer | bos@serpentine.com |
Portability | GHC |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Efficient locale-sensitive support for lazy text I/O.
The functions in this module obey the runtime system's locale, character set encoding, and line ending conversion settings.
If you know in advance that you will be working with data that has a specific encoding (e.g. UTF-8), and your application is highly performance sensitive, you may find that it is faster to perform I/O with bytestrings and to encode and decode yourself than to use the functions in this module.
Synopsis
- readFile :: FilePath -> IO Text
- writeFile :: FilePath -> Text -> IO ()
- appendFile :: FilePath -> Text -> IO ()
- hGetContents :: Handle -> IO Text
- hGetLine :: Handle -> IO Text
- hPutStr :: Handle -> Text -> IO ()
- hPutStrLn :: Handle -> Text -> IO ()
- interact :: (Text -> Text) -> IO ()
- getContents :: IO Text
- getLine :: IO Text
- putStr :: Text -> IO ()
- putStrLn :: Text -> IO ()
File-at-a-time operations
readFile :: FilePath -> IO Text Source #
Read a file and return its contents as a string. The file is
read lazily, as with getContents
.
Beware that this function (similarly to readFile
) is locale-dependent.
Unexpected system locale may cause your application to read corrupted data or
throw runtime exceptions about "invalid argument (invalid byte sequence)"
or "invalid argument (invalid character)". This is also slow, because GHC
first converts an entire input to UTF-32, which is afterwards converted to UTF-8.
If your data is UTF-8,
using decodeUtf8
.
readFile
is a much faster and safer alternative.
writeFile :: FilePath -> Text -> IO () Source #
Write a string to a file. The file is truncated to zero length before writing begins.