Permalink
Browse files

use openBinaryFile rather than openFile when opening binary files

  • Loading branch information...
JeroenFokker committed Feb 22, 2010
1 parent a824d80 commit 7eb4c466441201726993afda1b27184658abb43e
Showing with 7 additions and 6 deletions.
  1. +1 −1 SVNREVISION
  2. +3 −3 src/ehc/Base/Serialize.chs
  3. +3 −2 src/libutil/EH/Util/Binary.hs
View
@@ -1 +1 @@
-1789:1806M
+1821M
@@ -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)
@@ -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 ;
@@ -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
@@ -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 ;
@@ -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
}

0 comments on commit 7eb4c46

Please sign in to comment.