Created
July 17, 2015 13:50
-
-
Save taisyo7333/337554f967f29d844cd9 to your computer and use it in GitHub Desktop.
Haskell ByteString Samle
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
import System.Environment | |
import System.Directory -- openTempFile , removeFile | |
import System.IO | |
import Control.Exception -- bracketOnError | |
import qualified Data.ByteString.Lazy as B | |
{- | |
This code is referenced from "Learn You a Haskell for Great Good!!" | |
-} | |
main = do | |
( filename1:filename2:_) <- getArgs | |
copy filename1 filename2 | |
copy :: String -> String -> IO () | |
copy source dest = do | |
contents <- B.readFile source | |
bracketOnError (openTempFile "." "temp") | |
(\(tempPath, tempHandle) -> do | |
hClose tempHandle | |
removeFile tempPath) | |
(\(tempPath,tempHandle) -> do | |
B.hPutStr tempHandle contents | |
hClose tempHandle | |
renameFile tempPath dest | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment