Skip to content

Instantly share code, notes, and snippets.

@edofic
Created July 2, 2014 09:44
Show Gist options
  • Save edofic/6029eef1dfa9e9079f3e to your computer and use it in GitHub Desktop.
Save edofic/6029eef1dfa9e9079f3e to your computer and use it in GitHub Desktop.
file copy
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