From: Ramakrishnan Muthukrishnan Date: Sun, 17 May 2015 07:53:04 +0000 (+0530) Subject: create a dummy file on the disk for a given path X-Git-Url: https://git.rkrishnan.org/vdrive/components/com_hotproperty/css/class-simplejson.JSONEncoder-index.html?a=commitdiff_plain;h=4aca97ce9712460b0602bb91f44e87d7800886a8;p=functorrent.git create a dummy file on the disk for a given path --- diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs index 481f5da..d9ff929 100644 --- a/src/FuncTorrent/Peer.hs +++ b/src/FuncTorrent/Peer.hs @@ -5,10 +5,10 @@ module FuncTorrent.Peer msgLoop ) where -import Prelude hiding (lookup, concat, replicate, splitAt, empty) +import Prelude hiding (lookup, concat, replicate, splitAt, empty, writeFile) -import System.IO -import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton) +import System.IO (Handle, BufferMode(..), hSetBuffering) +import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton, writeFile) import Data.ByteString.Lazy (fromStrict, fromChunks) import qualified Data.ByteString.Char8 as BC (replicate, pack, length) import Network (connectTo, PortID(..)) @@ -157,6 +157,12 @@ bitfieldToList bs = go bs 0 in setBits ++ (go bs' (pos + 1)) +-- downloadPiece :: Integer -> Handle -> IO () + +createDummyFile :: FilePath -> Int -> IO () +createDummyFile path size = do + writeFile path (BC.replicate size '\0') + -- loop1 :: shake hands with all peers, find out the pieces they have, form PieceData. -- recvMsg :: Peer -> Handle -> Msg msgLoop :: Handle -> ByteString -> IO ()