git.iko.soy/typeable/pandoc
on rc/test4 help sign in
typeable/pandoc/data/make-reference-files.hs
27 lines 815 B history raw
1import System.Environment
2import System.Directory
3import Codec.Archive.Zip
4import qualified Data.ByteString.Lazy as BS
5import qualified Control.Exception as E
6import System.IO.Error (isDoesNotExistError)
7import System.FilePath
9mkzip :: String -> IO ()
10mkzip fmt = do
11 let dir = "data" </> fmt
12 output = "data" </> "reference" <.> fmt
13 cd <- getCurrentDirectory
14 setCurrentDirectory dir
15 archive <- addFilesToArchive [OptRecursive] emptyArchive ["."]
16 setCurrentDirectory cd
17 removeIfExists output
18 BS.writeFile output $ fromArchive archive
20removeIfExists :: FilePath -> IO ()
21removeIfExists fileName = removeFile fileName `E.catch` handleExists
22 where handleExists e
23 | isDoesNotExistError e = return ()
24 | otherwise = E.throwIO e
26main :: IO ()
27main = getArgs >>= mkzip . (!!0)