summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-05 17:51:58 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-05 17:51:58 +0400
commitb32f635684e88a4c9c4b873336624cdad05eb3e1 (patch)
tree6279b8d19b0a5f2122e1a02f0987657e877d4935 /src/Data
parent1d1786e518d673969724abe759ff5cfc71f67bfe (diff)
~ Add torrent path predicate.
Diffstat (limited to 'src/Data')
-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