module OpenAFP (
module OpenAFP.Types,
module OpenAFP.Records,
module OpenAFP.Internals,
module OpenAFP.Prelude.Utils,
module OpenAFP.Prelude.Lookups,
module OpenAFP.Prelude.Instances,
readAFP, writeAFP,
readArgs, afp_Chunks
) where
import OpenAFP.Types
import OpenAFP.Records
import OpenAFP.Internals
import OpenAFP.Prelude.Utils
import OpenAFP.Prelude.Lookups
import OpenAFP.Prelude.Instances
import qualified Data.ByteString.Lazy as L
afp_Chunks :: FilePath -> [AFP_]
afp_Chunks filename = unsafePerformIO $ readAFP filename
writeAFP :: (Binary a) => FilePath -> [a] -> IO ()
writeAFP "-" c = do
hSetBinaryMode stdout True
L.hPut stdout (encodeList c)
writeAFP filename c = encodeListFile filename c
instance RecChunk FilePath where
type ChunkOf FilePath = AFP_
readChunks = afp_Chunks
instance Rec Char
readAFP :: (MonadIO m) => FilePath -> m [AFP_]
readAFP "-" = io $ do
hSetBinaryMode stdin True
fmap decodeList (L.hGetContents stdin)
readAFP filename = io $ decodeListFile filename
readArgs :: (MonadIO m) => Int -> m [String]
readArgs n = io $ do
args <- getArgs
when ((length args) < n) $ do
pgm <- getProgName
putStrLn $ "Usage: " ++ pgm ++ " input.afp output.afp"
exitFailure
return args