Skip to content

Instantly share code, notes, and snippets.

@23Skidoo
Created May 7, 2011 15:34
Show Gist options
  • Save 23Skidoo/960585 to your computer and use it in GitHub Desktop.
Save 23Skidoo/960585 to your computer and use it in GitHub Desktop.
zcat with iterIO
module Main
where
import Control.Monad.IO.Class (MonadIO)
import Data.ByteString.Lazy (ByteString)
import Data.IterIO
import Data.IterIO.Zlib (inumGunzip)
import System.Environment
import System.IO
printUsage :: IO ()
printUsage = putStrLn "Usage: myZcat FILENAME"
main :: IO ()
main = do fs <- getArgs
case fs of
[] -> processInum $ enumHandle' stdin
_ | ("--help" `elem` fs) || ("-h" `elem` fs) -> printUsage
| otherwise -> processInum $ (foldr1 cat [enumFile' f | f <- fs])
-- TODO: read up on what that (IterR ByteString m ()) thingy does.
processInum :: MonadIO m => Onum ByteString m (IterR ByteString m ()) -> m ()
processInum i = i |. (inumRepeat inumGunzip) |$ stdoutI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment