summaryrefslogtreecommitdiff
path: root/Utility/Misc.hs
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2014-02-24 19:40:14 -0400
committerJoey Hess <joey@kitenet.net>2014-02-24 19:40:14 -0400
commit878e7471fa09dcc36b478e1ac1fd305d5a90b7bf (patch)
treed552b8faa43078e3dfe1f8b10063ec566eced4e2 /Utility/Misc.hs
parentd80c547a7d1261f158148ca85e627cc2ecb005f2 (diff)
downloadgit-repair-878e7471fa09dcc36b478e1ac1fd305d5a90b7bf.tar.gz
merge from git-annex
Diffstat (limited to 'Utility/Misc.hs')
-rw-r--r--Utility/Misc.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/Utility/Misc.hs b/Utility/Misc.hs
index 68199c8..20007ad 100644
--- a/Utility/Misc.hs
+++ b/Utility/Misc.hs
@@ -33,13 +33,20 @@ 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
+{- Reads a file strictly, and using the FileSystemEncoding, 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
+{- Writes a file, using the FileSystemEncoding so it will never crash
+ - on a badly encoded content string. -}
+writeFileAnyEncoding :: FilePath -> String -> IO ()
+writeFileAnyEncoding f content = withFile f WriteMode $ \h -> do
+ fileEncoding h
+ hPutStr h content
+
{- Like break, but the item matching the condition is not included
- in the second result list.
-