Skip to content

Commit

Permalink
use openBinaryFile rather than openFile when opening binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenFokker committed Feb 22, 2010
1 parent a824d80 commit 7eb4c46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SVNREVISION
@@ -1 +1 @@
1789:1806M
1821M
6 changes: 3 additions & 3 deletions src/ehc/Base/Serialize.chs
Expand Up @@ -77,7 +77,7 @@ instance Serialize Foo where

%%[20 import(qualified {%{EH}Base.Binary} as Bn)
%%]
%%[20 import(qualified Data.ByteString.Lazy as L, IO)
%%[20 import(qualified Data.ByteString.Lazy as L, IO, System.IO(openBinaryFile))
%%]

%%[20 import(EH.Util.Utils)
Expand Down Expand Up @@ -396,15 +396,15 @@ unserialize = St.evalStateT sget (SGetS Map.empty)
-- | Serialize to FilePath
putSerializeFile :: Serialize a => FilePath -> a -> IO ()
putSerializeFile fn x
= do { h <- openFile fn WriteMode
= do { h <- openBinaryFile fn WriteMode
; L.hPut h (Bn.runPut $ serialize x)
; hClose h
}

-- | Unserialize from FilePath
getSerializeFile :: Serialize a => FilePath -> IO a
getSerializeFile fn
= do { h <- openFile fn ReadMode
= do { h <- openBinaryFile fn ReadMode
; b <- liftM (Bn.runGet unserialize) (L.hGetContents h)
-- ; hClose h
; return b ;
Expand Down
5 changes: 3 additions & 2 deletions src/libutil/EH/Util/Binary.hs
Expand Up @@ -22,6 +22,7 @@ import Data.Binary
import Data.Binary.Put(runPut,putWord16be)
import Data.Binary.Get(runGet,getWord16be)
import IO
import System.IO(openBinaryFile)
import Control.Monad

import EH.Util.FPath
Expand All @@ -38,7 +39,7 @@ hGetBinary h
-- | Decode from FilePath
getBinaryFile :: Binary a => FilePath -> IO a
getBinaryFile fn
= do { h <- openFile fn ReadMode
= do { h <- openBinaryFile fn ReadMode
; b <- hGetBinary h
-- ; hClose h
; return b ;
Expand All @@ -61,7 +62,7 @@ hPutBinary h pt
-- | Encode to FilePath
putBinaryFile :: Binary a => FilePath -> a -> IO ()
putBinaryFile fn pt
= do { h <- openFile fn WriteMode
= do { h <- openBinaryFile fn WriteMode
; hPutBinary h pt
; hClose h
}
Expand Down

0 comments on commit 7eb4c46

Please sign in to comment.