| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Pipes.Safe.Prelude
Description
Simple resource management functions
Synopsis
- withFile :: MonadSafe m => FilePath -> IOMode -> (Handle -> m r) -> m r
- withBinaryFile :: MonadSafe m => FilePath -> IOMode -> (Handle -> m r) -> m r
- openFile :: MonadSafe m => FilePath -> IOMode -> m (ReleaseKey, Handle)
- openBinaryFile :: MonadSafe m => FilePath -> IOMode -> m (ReleaseKey, Handle)
- readFile :: MonadSafe m => FilePath -> Producer' String m ()
- writeFile :: MonadSafe m => FilePath -> Consumer' String m r
- allocate :: MonadSafe m => Base m a -> (a -> Base m ()) -> m (ReleaseKey, a)
- allocate_ :: MonadSafe m => Base m a -> Base m () -> m ReleaseKey
Handle management
withFile :: MonadSafe m => FilePath -> IOMode -> (Handle -> m r) -> m r Source #
Acquire a Handle within MonadSafe
The file is opened in text mode. See also: withBinaryFile
withBinaryFile :: MonadSafe m => FilePath -> IOMode -> (Handle -> m r) -> m r Source #
Like withFile, but open the file in binary mode
See hSetBinaryMode for the differences between binary and text mode.
openFile :: MonadSafe m => FilePath -> IOMode -> m (ReleaseKey, Handle) Source #
Acquire a Handle within MonadSafe
The ReleaseKey can be used to close the handle with release;
otherwise the handle will be closed automatically at the conclusion of the
MonadSafe block.
The file is opened in text mode. See also: openBinaryFile
openBinaryFile :: MonadSafe m => FilePath -> IOMode -> m (ReleaseKey, Handle) Source #
Like openFile, but open the file in binary mode
See hSetBinaryMode for the differences between binary and text mode.
String I/O
Note that Strings are very inefficient, and I will release future separate
packages with ByteString and Text operations.
I only provide these to allow users to test simple I/O without requiring any
additional library dependencies.
readFile :: MonadSafe m => FilePath -> Producer' String m () Source #
Read lines from a file, automatically opening and closing the file as necessary
writeFile :: MonadSafe m => FilePath -> Consumer' String m r Source #
Write lines to a file, automatically opening and closing the file as necessary
Registering/releasing
Arguments
| :: MonadSafe m | |
| => Base m a | Acquire |
| -> (a -> Base m ()) | Release |
| -> m (ReleaseKey, a) |
Acquire some resource with a guarantee that it will eventually be released
The ReleaseKey can be passed to release to
release the resource manually. If this has not been done by the end
of the MonadSafe block, the resource will be released automatically.
Arguments
| :: MonadSafe m | |
| => Base m a | Acquire |
| -> Base m () | Release |
| -> m ReleaseKey |
Like allocate, but for when the resource itself is not needed
The acquire action runs immediately. The ReleaseKey can be passed
to release to run the release action. If this has not been
done by the end of the MonadSafe block, the release action will be
run automatically.