summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Data/Torrent.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 19365481..e5e90a93 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -28,6 +28,7 @@ module Data.Torrent
28 ( -- * Torrent 28 ( -- * Torrent
29 Torrent(..), ContentInfo(..), FileInfo(..) 29 Torrent(..), ContentInfo(..), FileInfo(..)
30 , torrent, simpleTorrent 30 , torrent, simpleTorrent
31 , torrentExt, isTorrentPath
31 , fromFile 32 , fromFile
32 33
33 -- * Files layout 34 -- * Files layout
@@ -457,11 +458,18 @@ pieceHash ci ix = slice (hashsize * ix) hashsize (ciPieces ci)
457 458
458-- | Validate piece with metainfo hash. 459-- | Validate piece with metainfo hash.
459checkPiece :: ContentInfo -> Int -> ByteString -> Bool 460checkPiece :: ContentInfo -> Int -> ByteString -> Bool
460checkPiece ci ix piece @ (PS _ off si) 461checkPiece ci ix piece
461 | traceShow (ix, off, si) True
462 = B.length piece == ciPieceLength ci 462 = B.length piece == ciPieceLength ci
463 && C.hash piece == pieceHash ci ix 463 && C.hash piece == pieceHash ci ix
464 464
465-- | Extension usually used for torrent metafiles.
466torrentExt :: String
467torrentExt = "torrent"
468
469-- | Test if this path has proper extension.
470isTorrentPath :: FilePath -> Bool
471isTorrentPath filepath = takeExtension filepath == extSeparator : torrentExt
472
465-- | Read and decode a .torrent file. 473-- | Read and decode a .torrent file.
466fromFile :: FilePath -> IO Torrent 474fromFile :: FilePath -> IO Torrent
467fromFile filepath = do 475fromFile filepath = do