Commit 90d43b76 authored by Francesco Gazzetta's avatar Francesco Gazzetta
Browse files

use withFile instead of an explicit bracket

parent 0bc3cf2e
......@@ -129,8 +129,8 @@ wrapLine width = wrap 0 []
--
withFileContents :: FilePath -> (String -> NoCallStackIO a) -> NoCallStackIO a
withFileContents name action =
Exception.bracket (openFile name ReadMode) hClose
(\hnd -> hGetContents hnd >>= action)
Exception.withFile name ReadMode
(\hnd -> hGetContents hnd >>= action)
-- | Writes a file atomically.
--
......@@ -254,9 +254,7 @@ readUTF8File f = fmap (ignoreBOM . fromUTF8)
--
withUTF8FileContents :: FilePath -> (String -> IO a) -> IO a
withUTF8FileContents name action =
Exception.bracket
(openBinaryFile name ReadMode)
hClose
Exception.withBinaryFile name ReadMode
(\hnd -> hGetContents hnd >>= action . ignoreBOM . fromUTF8)
-- | Writes a Unicode String as a UTF8 encoded text file.
......
......@@ -389,7 +389,7 @@ diff args path1 path2 = do
-- | Write a file with no CRs, always.
writeFileNoCR :: FilePath -> String -> IO ()
writeFileNoCR f s =
E.bracket (openFile f WriteMode) hClose $ \h -> do
E.withFile f WriteMode $ \h -> do
hSetNewlineMode h noNewlineTranslation
hPutStr h s
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment