module Data.Conf.Json
(readParse) where
import Control.Monad
import Data.Aeson as A
import Data.ByteString as B
import Data.ByteString.Lazy as L
import Prelude as P
import System.Directory as D
import System.IO as I
readParse::FromJSON conf =>
FilePath -> IO (Either String conf)
readParse fullPath0 = do
tbs1 <- readEntireFile fullPath0::IO (Either String B.ByteString)
pure $ toLazy <$> tbs1 >>=
eitherDecode'
where toLazy::B.ByteString -> L.ByteString
toLazy bs0 = L.fromChunks [bs0]
readEntireFile::FilePath -> IO (Either String B.ByteString)
readEntireFile path0 = do
exists1 <- doesFileExist path0
if exists1 then liftM Right $
withBinaryFile path0 ReadMode B.hGetContents
else pure $ Left $ "file n/a: " ++ path0