From 4aca97ce9712460b0602bb91f44e87d7800886a8 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Sun, 17 May 2015 13:23:04 +0530 Subject: [PATCH] create a dummy file on the disk for a given path --- src/FuncTorrent/Peer.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 () -- 2.37.2