+ let filePath = name (info m) -- really this is just the file name, not file path
+ fileLen = lengthInBytes (info m)
+ pieceHash = pieces (info m)
+ pLen = pieceLength (info m)
+ defaultPieceMap = initPieceMap pieceHash fileLen pLen
+ log $ "Downloading file : " ++ filePath
+ dfe <- doesFileExist filePath
+ pieceMap <- if dfe
+ then
+ pieceMapFromFile filePath defaultPieceMap
+ else do
+ -- create a dummy file
+ _ <- writeFile filePath (replicate (fromIntegral fileLen) '\0')
+ return defaultPieceMap