ips/main/ips.hs
2021-02-24 16:28:47 +01:00

27 lines
704 B
Haskell

module Main (main) where
import IPS (Bytes, makeBytes)
import qualified IPS
import System.Environment
import System.IO
import qualified Data.ByteString as ByteString
import qualified Data.Vector.Storable as Vector
main :: IO ()
main = do
args <- getArgs
case args of
[inf, ipsf, outf] -> do
buf <- readBytes inf
ips <- either error id <$> IPS.read ipsf
writeBytes outf $ IPS.apply ips buf
_ -> error "usage: $0 <in> <ips> <out>"
readBytes :: FilePath -> IO Bytes
readBytes f = makeBytes <$> ByteString.readFile f
writeBytes :: FilePath -> Bytes -> IO ()
writeBytes f buf =
withFile f WriteMode \h ->
Vector.unsafeWith buf \ptr ->
hPutBuf h ptr (Vector.length buf)