{-# LANGUAGE ScopedTypeVariables #-}

module HaskellWorks.Data.Xml.Succinct.Cursor.Load
  ( loadSlowCursor
  , loadFastCursor
  ) where

import HaskellWorks.Data.Xml.Succinct.Cursor.Create
import HaskellWorks.Data.Xml.Succinct.Cursor.Types

import qualified Data.ByteString as BS

-- | Load an XML file into memory and return a raw cursor initialised to the
-- start of the XML document.
loadSlowCursor :: FilePath -> IO SlowCursor
loadSlowCursor :: FilePath -> IO SlowCursor
loadSlowCursor = (ByteString -> SlowCursor) -> IO ByteString -> IO SlowCursor
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> SlowCursor
byteStringAsSlowCursor (IO ByteString -> IO SlowCursor)
-> (FilePath -> IO ByteString) -> FilePath -> IO SlowCursor
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> IO ByteString
BS.readFile

-- | Load an XML file into memory and return a query-optimised cursor initialised
-- to the start of the XML document.
loadFastCursor :: FilePath -> IO FastCursor
loadFastCursor :: FilePath -> IO FastCursor
loadFastCursor = (ByteString -> FastCursor) -> IO ByteString -> IO FastCursor
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> FastCursor
byteStringAsFastCursor (IO ByteString -> IO FastCursor)
-> (FilePath -> IO ByteString) -> FilePath -> IO FastCursor
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> IO ByteString
BS.readFile