module Holumbus.Index.Common.LoadStore
where
import Data.Binary ( Binary (..) )
import qualified
Data.Binary as B
import qualified
Data.List as L
import Text.XML.HXT.Core
loadFromFile :: (XmlPickler a, Binary a) => FilePath -> IO a
loadFromFile f = if L.isSuffixOf ".xml" f then loadFromXmlFile f else loadFromBinFile f
loadFromXmlFile :: XmlPickler a => FilePath -> IO a
loadFromXmlFile f = do
r <- runX (xunpickleDocument xpickle options f)
return $! head r
where
options = [ withRemoveWS yes, withInputEncoding utf8, withValidate no ]
writeToXmlFile :: XmlPickler a => FilePath -> a -> IO ()
writeToXmlFile f i = do
runX (constA i >>> xpickleDocument xpickle options f)
>> return ()
where
options = [ withIndent yes, withOutputEncoding utf8 ]
loadFromBinFile :: Binary a => FilePath -> IO a
loadFromBinFile = B.decodeFile
writeToBinFile :: Binary a => FilePath -> a -> IO ()
writeToBinFile = B.encodeFile