-- | Encoding agnostic i/o.
module Sound.Sc3.Server.Graphdef.Io where

import Data.List {- base -}

import Sound.Sc3.Server.Graphdef {- hsc3 -}
import qualified Sound.Sc3.Server.Graphdef.Binary as Binary {- hsc3 -}
import qualified Sound.Sc3.Server.Graphdef.Text as Text {- hsc3 -}

{- | Encoding agnostic file reader.
If the file has a .scsyndef.text extension it's read as a text file, else as a binary file.

read_graphdef_file "/tmp/stsc3.scsyndef.text"
-}
read_graphdef_file :: FilePath -> IO Graphdef
read_graphdef_file :: FilePath -> IO Graphdef
read_graphdef_file FilePath
fn =
  if FilePath
".scsyndef.text" forall a. Eq a => [a] -> [a] -> Bool
`isSuffixOf` FilePath
fn
  then FilePath -> IO Graphdef
Text.read_graphdef_file FilePath
fn
  else FilePath -> IO Graphdef
Binary.read_graphdef_file FilePath
fn