Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
31eddce7
Commit
31eddce7
authored
Sep 20, 2016
by
Herbert Valerio Riedel
🕺
Browse files
Add C.D.Compat.Binary.{encodeFile,decodeFileOrFail'}
parent
f91e65a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Cabal/Distribution/Compat/Binary.hs
View file @
31eddce7
...
...
@@ -9,11 +9,12 @@
module
Distribution.Compat.Binary
(
decodeOrFailIO
,
decodeFileOrFail'
#
if
__GLASGOW_HASKELL__
>=
708
||
MIN_VERSION_binary
(
0
,
7
,
0
)
,
module
Data
.
Binary
#
else
,
Binary
(
..
)
,
decode
,
encode
,
decode
,
encode
,
encodeFile
#
endif
)
where
...
...
@@ -33,15 +34,21 @@ import Data.ByteString.Lazy (ByteString)
import
Data.Binary
-- | Lazily reconstruct a value previously written to a file.
decodeFileOrFail'
::
Binary
a
=>
FilePath
->
IO
(
Either
String
a
)
decodeFileOrFail'
f
=
either
(
Left
.
snd
)
Right
`
fmap
`
decodeFileOrFail
f
#
else
import
Data.Binary.Get
import
Data.Binary.Put
import
qualified
Data.ByteString.Lazy
as
BSL
import
Distribution.Compat.Binary.Class
import
Distribution.Compat.Binary.Generic
()
-- | Decode a value from a lazy ByteString, reconstructing the original structure.
-- | Decode a value from a lazy ByteString, reconstructing the
-- original structure.
--
decode
::
Binary
a
=>
ByteString
->
a
decode
=
runGet
get
...
...
@@ -52,6 +59,14 @@ encode :: Binary a => a -> ByteString
encode
=
runPut
.
put
{-# INLINE encode #-}
-- | Lazily reconstruct a value previously written to a file.
decodeFileOrFail'
::
Binary
a
=>
FilePath
->
IO
(
Either
String
a
)
decodeFileOrFail'
f
=
decodeOrFailIO
=<<
BSL
.
readFile
f
-- | Lazily serialise a value to a file
encodeFile
::
Binary
a
=>
FilePath
->
a
->
IO
()
encodeFile
f
=
BSL
.
writeFile
f
.
encode
#
endif
decodeOrFailIO
::
Binary
a
=>
ByteString
->
IO
(
Either
String
a
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment