mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
simplification: decodeFile doesn't have to check that the file is empty anymore
This commit is contained in:
@@ -264,18 +264,10 @@ encodeFile f v = L.writeFile f (encode v)
|
|||||||
--
|
--
|
||||||
-- > return . decode . decompress =<< B.readFile f
|
-- > return . decode . decompress =<< B.readFile f
|
||||||
--
|
--
|
||||||
-- After contructing the data from the input file, 'decodeFile' checks
|
|
||||||
-- if the file is empty, and in doing so will force the associated file
|
|
||||||
-- handle closed, if it is indeed empty. If the file is not empty,
|
|
||||||
-- it is up to the decoding instance to consume the rest of the data,
|
|
||||||
-- or otherwise finalise the resource.
|
|
||||||
--
|
|
||||||
decodeFile :: Binary a => FilePath -> IO a
|
decodeFile :: Binary a => FilePath -> IO a
|
||||||
decodeFile f = bracket (openBinaryFile f ReadMode) hClose $ \h -> do
|
decodeFile f = bracket (openBinaryFile f ReadMode) hClose $ \h -> do
|
||||||
s <- L.hGetContents h
|
s <- L.hGetContents h
|
||||||
evaluate $ runGet (do v <- get
|
evaluate $ runGet get s
|
||||||
m <- isEmpty
|
|
||||||
m `seq` return v) s
|
|
||||||
|
|
||||||
-- needs bytestring 0.9.1.x to work
|
-- needs bytestring 0.9.1.x to work
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user