withFile -package:unliftio

The computation withFile path mode action opens the file and runs action 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 withFile path mode act is preferable to
openFile path mode >>= (\hdl -> act hdl >>= hClose hdl)
See also: bracket
withFile name mode act opens a file like openFile and passes the resulting handle to the computation act. The handle will be closed on exit from withFile, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act.
Acquire a Handle within MonadSafe The file is opened in text mode. See also: withBinaryFile
Open a file in binary mode, and pass its Handle to a provided computation. The Handle will be automatically closed when the computation returns. This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.
Create a temporary file with the given contents and execute the given action. The file is removed after the action has completed.
withFile name mode act opens a file using openFile and passes the resulting handle to the computation act. The handle will be closed on exit from withFile, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act. Pre-release
Like withFile, but sets the file encoding to UTF-8, regardless of the current locale.
withFile filepath mode act opens a file using the mode and run act. the by-product handle will be closed when act finish, either normally or through an exception. The value returned is the result of act@
Run an action on a file. The Handle is automatically closed afther the action.
Like withFile, but takes a PlatformPath instead of an OsPath.
Wrapper around withFile
Acquire a file handle and perform an I/O action. The file will be closed on exit or when this I/O action throws an exception.
Open audio file located at specified path, execute some actions given its FileId and then free the file.
Open a file and perform an action on its handle
withFileBlocking name mode act opens a file like openFileBlocking and passes the resulting handle to the computation act. The handle will be closed on exit from withFileBlocking, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act.
Gets the contents of a file, but guarantee that it gets closed. The file is read lazily; if it is not fully consumed by the action then an exception is thrown.
Creating a file information cache and executing the action in the second argument. The first argument is a cache duration in microseconds.