Skip to content

Instantly share code, notes, and snippets.

@queertypes
Created February 21, 2014 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queertypes/9140274 to your computer and use it in GitHub Desktop.
Save queertypes/9140274 to your computer and use it in GitHub Desktop.
Rread file at path, compress, write to path.gz
{-# LANGUAGE OverloadedStrings #-}
import System.Environment (getArgs)
import qualified Codec.Compression.GZip as GZ (compress)
import qualified Data.ByteString.Lazy as LB
main :: IO ()
main = do
-- Get arguments - a path; lift the pure operation 'head' into the IO context
path <- fmap head getArgs
-- read the contents of the file in lazily
contents <- LB.readFile path
-- write the compressed contents of the file to <path>.gz
-- lazily
LB.writeFile (path ++ ".gz") $ GZ.compress contents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment