Bryan O'Sullivan avatar Bryan O'Sullivan committed 0188614

Trim down the number of functions that need 6.12-specific implementations.

Comments (0)

Files changed (1)

 import GHC.IO.Handle.Text (commitBuffer')
 import GHC.IO.Handle.Types (BufferList(..), BufferMode(..), Handle__(..),
                             Newline(..))
+import System.IO (IOMode(..), openFile, withFile)
 #endif
 
 -- | The 'readFile' function reads a file and returns the contents of
 -- the file as a string.  The entire file is read strictly, as with
 -- 'getContents'.
 readFile :: FilePath -> IO Text
-#if __GLASGOW_HASKELL__ <= 610
-readFile = fmap decodeUtf8 . B.readFile
-#else
-readFile = undefined
-#endif
+readFile name = openFile name ReadMode >>= hGetContents
 
 -- | Write a string to a file.  The file is truncated to zero length
 -- before writing begins.
 writeFile :: FilePath -> Text -> IO ()
-#if __GLASGOW_HASKELL__ <= 610
-writeFile p = B.writeFile p . encodeUtf8
-#else
-writeFile = undefined
-#endif
+writeFile p = withFile p WriteMode . flip hPutStr
 
 -- | Write a string the end of a file.
 appendFile :: FilePath -> Text -> IO ()
-#if __GLASGOW_HASKELL__ <= 610
-appendFile p = B.appendFile p . encodeUtf8
-#else
-appendFile = undefined
-#endif
+appendFile p = withFile p AppendMode . flip hPutStr
 
 -- | Read the remaining contents of a handle as a string.
 hGetContents :: Handle -> IO Text
 
 -- | Write a string to a handle, followed by a newline.
 hPutStrLn :: Handle -> Text -> IO ()
-#if __GLASGOW_HASKELL__ <= 610
-hPutStrLn h t = B.hPutStrLn h (encodeUtf8 t) >> hPutChar h '\n'
-#else
 hPutStrLn h t = hPutStr h t >> hPutChar h '\n'
-#endif
 
 -- | The 'interact' function takes a function of type @Text -> Text@
 -- as its argument. The entire input from the standard input device is
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.