From 655fa61307f580c400072be12f9e5f3be3cef4a8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Nov 2013 13:42:25 -0400 Subject: merge from git-annex --- Utility/Misc.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Utility/Misc.hs') diff --git a/Utility/Misc.hs b/Utility/Misc.hs index 4b0e9a1..68199c8 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -21,6 +21,9 @@ import System.Posix.Process (getAnyProcessStatus) import Utility.Exception #endif +import Utility.FileSystemEncoding +import Utility.Monad + {- A version of hgetContents that is not lazy. Ensures file is - all read before it gets closed. -} hGetContentsStrict :: Handle -> IO String @@ -30,6 +33,13 @@ hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s readFileStrict :: FilePath -> IO String readFileStrict = readFile >=> \s -> length s `seq` return s +{- Reads a file strictly, and using the FileSystemEncofing, so it will + - never crash on a badly encoded file. -} +readFileStrictAnyEncoding :: FilePath -> IO String +readFileStrictAnyEncoding f = withFile f ReadMode $ \h -> do + fileEncoding h + hClose h `after` hGetContentsStrict h + {- Like break, but the item matching the condition is not included - in the second result list. - -- cgit v1.2.3