ips/main/ips.hs

28 lines
704 B
Haskell
Raw Normal View History

2021-02-24 10:27:30 -05:00
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)