Created
February 21, 2014 18:30
-
-
Save queertypes/9140274 to your computer and use it in GitHub Desktop.
Rread file at path, compress, write to path.gz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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