-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b35c49
commit a0c30b7
Showing
6 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- | Wrappers for Yaml functions to workaround | ||
-- https://github.com/commercialhaskell/stack/issues/2491. | ||
-- Import Data.Yaml.Extra in place of Data.Yaml to use this workaround. | ||
-- Beware these functions construct/deconstruct the entire file at once! | ||
module Data.Yaml.Extra (decodeFileEither, encodeFile, module Data.Yaml) where | ||
|
||
import Data.Yaml hiding (decodeFileEither, encodeFile) | ||
import qualified Data.ByteString as B | ||
import System.IO | ||
|
||
-- Note: we refrain from using 'B.readFile' and 'B.writeFile', as they open | ||
-- the file in binary mode rather than text mode. | ||
decodeFileEither :: FromJSON a => FilePath -> IO (Either ParseException a) | ||
decodeFileEither path = withFile path ReadMode $ | ||
\hnd -> do | ||
fileContent <- B.hGetContents hnd | ||
return $ decodeEither' fileContent | ||
|
||
encodeFile :: ToJSON a => FilePath -> a -> IO () | ||
encodeFile path v = withFile path WriteMode $ | ||
\hnd -> do | ||
let fileContent = encode v | ||
B.hPut hnd fileContent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters