Skip to content

Commit

Permalink
Add openBinaryTempFile
Browse files Browse the repository at this point in the history
  • Loading branch information
augustss committed Sep 26, 2024
1 parent aa21404 commit eaa2e8d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/System/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module System.IO(

mkTextEncoding, hSetEncoding, utf8,

openTmpFile, openTempFile,
openTmpFile, openTempFile, openBinaryTempFile,

withFile,
) where
Expand Down Expand Up @@ -301,8 +301,8 @@ openTmpFile tmpl = do
return (tmp, h)

-- Sloppy implementation of openTempFile
openTempFile :: FilePath -> String -> IO (String, Handle)
openTempFile tmp tmplt = do
openTempFile' :: (FilePath -> IOMode -> IO Handle) -> FilePath -> String -> IO (String, Handle)
openTempFile' open tmp tmplt = do
let (pre, suf) = splitTmp tmplt
loop n = do
let fn = tmp ++ "/" ++ pre ++ show n ++ suf
Expand All @@ -312,6 +312,12 @@ openTempFile tmp tmplt = do
hClose h
loop (n+1 :: Int)
Nothing -> do
h <- openFile fn ReadWriteMode
h <- open fn ReadWriteMode
return (fn, h)
loop 0

openTempFile :: FilePath -> String -> IO (String, Handle)
openTempFile = openTempFile' openFile

openBinaryTempFile :: FilePath -> String -> IO (String, Handle)
openBinaryTempFile = openTempFile' openBinaryFile

0 comments on commit eaa2e8d

Please sign in to comment.