Copyright | (c) The University of Glasgow 2017 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | libraries@haskell.org |
Stability | internal |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
This model abstracts away the platform specific handles that can be toggled through the RTS.
Synopsis
- stdin :: Handle
- stdout :: Handle
- stderr :: Handle
- openFile :: FilePath -> IOMode -> IO Handle
- openBinaryFile :: FilePath -> IOMode -> IO Handle
- openFileBlocking :: FilePath -> IOMode -> IO Handle
- withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
- withBinaryFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
- withFileBlocking :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
Documentation
:: FilePath | The path to the file that should be opened |
-> IOMode | The mode in which the file should be opened |
-> IO Handle |
The computation
returns a file handle that can be
used to interact with the file.openFile
path mode
The handle is open in text mode with localeEncoding
.
You can change the encoding with hSetEncoding
.
:: FilePath | The path to the binary file that should be opened |
-> IOMode | The mode in which the binary file should be opened |
-> IO Handle |
The computation
returns a file handle that can be
used to interact with the binary file.openBinaryFile
path mode
This is different from openFile
as in that it does not use any file encoding.
:: FilePath | The path to the file that should be opened |
-> IOMode | The mode in which the file should be opened |
-> (Handle -> IO r) | The action to run with the obtained handle |
-> IO r |
The computation
opens the file and runs withFile
path mode actionaction
with the obtained handle before closing the file.
Even when an exception is raised within the action
, the file will still be closed.
This is why
is preferable towithFile
path mode act
openFile
path mode >>= (\hdl -> act hdl >>=hClose
hdl)
See also: bracket
withBinaryFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r Source #
The computation
opens the binary file
and runs withBinaryFile
path mode actionaction
with the obtained handle before closing the binary file.
This is different from withFile
as in that it does not use any file encoding.
Even when an exception is raised within the action
, the file will still be closed.
This is why
is preferable towithBinaryFile
path mode act
openBinaryFile
path mode >>= (\hdl -> act hdl >>=hClose
hdl)
See also: bracket