Created
July 2, 2014 09:44
-
-
Save edofic/6029eef1dfa9e9079f3e to your computer and use it in GitHub Desktop.
file copy
This file contains hidden or 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
module Main where | |
import System.Environment (getArgs) | |
import System.IO (withFile, Handle, IOMode(ReadMode, WriteMode)) | |
import Data.ByteString as BS | |
blockSize :: Int | |
blockSize = 32 * 1024 | |
streamCopy :: Handle -> Handle -> IO () | |
streamCopy from to = go where | |
go = do | |
buffer <- hGet from blockSize | |
if BS.length buffer > 0 | |
then do | |
hPut to buffer | |
go | |
else | |
return () | |
main = do | |
[fromPth, toPth] <- getArgs | |
withFile fromPth ReadMode $ \fromH -> | |
withFile toPth WriteMode $ \toH -> | |
streamCopy fromH toH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment