File: String.hs

package info (click to toggle)
git-annex 10.20251029-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 75,300 kB
  • sloc: haskell: 91,492; javascript: 9,103; sh: 1,593; makefile: 216; perl: 137; ansic: 44
file content (38 lines) | stat: -rw-r--r-- 967 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{- Functions that operate on OsPath, but treat the contents of files as
 - Strings.
 -
 - These functions all set the close-on-exec flag to True, unlike
 - the Prelude versions.
 -
 - Copyright 2025 Joey Hess <id@joeyh.name>
 -
 - License: BSD-2-clause
 -}

{-# OPTIONS_GHC -fno-warn-tabs #-}
{-# LANGUAGE CPP #-}

module Utility.FileIO.String
(
#ifdef WITH_OSPATH
	readFileString,
	writeFileString,
	appendFileString,
#endif
) where

#ifdef WITH_OSPATH
import qualified Utility.FileIO.CloseOnExec as I
import Utility.OsPath (OsPath)
import Prelude (String, IO, (>>=))
import System.IO (IOMode(..), hGetContents, hPutStr)

readFileString :: OsPath -> IO String
readFileString f = I.openFile f ReadMode >>= hGetContents

writeFileString :: OsPath -> String -> IO ()
writeFileString f txt = I.withFile f WriteMode (\hdl -> hPutStr hdl txt)

appendFileString :: OsPath -> String -> IO ()
appendFileString f txt = I.withFile f AppendMode (\hdl -> hPutStr hdl txt)
#endif