git.iko.soy/typeable/pandoc
on aa49dec help sign in
typeable/pandoc/data/make-reference-files.hs
26 lines 782 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)
8mkzip :: String -> IO ()
9mkzip fmt = do
10 let dir = "data/"++fmt
11 output = "data/reference."++fmt
12 cd <- getCurrentDirectory
13 setCurrentDirectory dir
14 archive <- addFilesToArchive [OptRecursive] emptyArchive ["."]
15 setCurrentDirectory cd
16 removeIfExists output
17 BS.writeFile output $ fromArchive archive
19removeIfExists :: FilePath -> IO ()
20removeIfExists fileName = removeFile fileName `E.catch` handleExists
21 where handleExists e
22 | isDoesNotExistError e = return ()
23 | otherwise = E.throwIO e
25main :: IO ()
26main = getArgs >>= mkzip . (!!0)