1
0
forked from GitHub/gf-core

explicitly close the file handle in Data.Binary.decodeFile

This commit is contained in:
krasimir
2009-06-24 10:39:03 +00:00
parent 9e3131f169
commit cf4efe0acc

View File

@@ -64,6 +64,7 @@ import Data.Binary.Put
import Data.Binary.Get import Data.Binary.Get
import Control.Monad import Control.Monad
import Control.Exception
import Foreign import Foreign
import System.IO import System.IO
@@ -270,11 +271,11 @@ encodeFile f v = L.writeFile f (encode v)
-- or otherwise finalise the resource. -- or otherwise finalise the resource.
-- --
decodeFile :: Binary a => FilePath -> IO a decodeFile :: Binary a => FilePath -> IO a
decodeFile f = do decodeFile f = bracket (openFile f ReadMode) hClose $ \h -> do
s <- L.readFile f s <- L.hGetContents h
return $! runGet (do v <- get evaluate $ runGet (do v <- get
m <- isEmpty m <- isEmpty
m `seq` return v) s m `seq` return v) s
-- needs bytestring 0.9.1.x to work -- needs bytestring 0.9.1.x to work