diff options
-rw-r--r-- | src/Data/Torrent.hs | 12 |
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. |
459 | checkPiece :: ContentInfo -> Int -> ByteString -> Bool | 460 | checkPiece :: ContentInfo -> Int -> ByteString -> Bool |
460 | checkPiece ci ix piece @ (PS _ off si) | 461 | checkPiece 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. | ||
466 | torrentExt :: String | ||
467 | torrentExt = "torrent" | ||
468 | |||
469 | -- | Test if this path has proper extension. | ||
470 | isTorrentPath :: FilePath -> Bool | ||
471 | isTorrentPath filepath = takeExtension filepath == extSeparator : torrentExt | ||
472 | |||
465 | -- | Read and decode a .torrent file. | 473 | -- | Read and decode a .torrent file. |
466 | fromFile :: FilePath -> IO Torrent | 474 | fromFile :: FilePath -> IO Torrent |
467 | fromFile filepath = do | 475 | fromFile filepath = do |