-mkPieceMap :: Integer -> ByteString -> [Integer] -> PieceMap
-mkPieceMap numPieces pieceHash pLengths = fromList kvs
- where kvs = [(i, PieceData { peers = []
- , dlstate = Pending
- , hash = h
- , len = pLen })
- | (i, h, pLen) <- zip3 [0..numPieces] hashes pLengths]
- hashes = splitN 20 pieceHash
+initPieceMap :: ByteString -> Integer -> Integer -> PieceMap
+initPieceMap pieceHash fileLen pieceLen = fromList kvs
+ where
+ numPieces = (toInteger . (`quot` 20) . BC.length) pieceHash
+ kvs = [(i, PieceData { peers = []
+ , dlstate = Pending
+ , hash = h
+ , len = pLen })
+ | (i, h, pLen) <- zip3 [0..numPieces] hashes pLengths]
+ hashes = splitN 20 pieceHash
+ pLengths = (splitNum fileLen pieceLen)