summaryrefslogtreecommitdiff
path: root/src/Data/Torrent.hs
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-24 01:15:15 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-24 01:15:15 +0400
commitd616ca9030d5420ff43e48c5b06738bec7230fc7 (patch)
treedc3a30e892ec66038046c9b3ea95ed1a4509a57b /src/Data/Torrent.hs
parent0411025eb72ce0f5e5484b770d126779221b7c34 (diff)
+ Add root path to contentLayout.
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r--src/Data/Torrent.hs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 226126f2..47a09cf5 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -17,6 +17,7 @@ module Data.Torrent
17 ) where 17 ) where
18 18
19import Control.Applicative 19import Control.Applicative
20import Control.Arrow
20import qualified Data.Map as M 21import qualified Data.Map as M
21import Data.ByteString (ByteString) 22import Data.ByteString (ByteString)
22import qualified Data.ByteString as B 23import qualified Data.ByteString as B
@@ -236,19 +237,19 @@ pieceCount ti = contentLength ti `sizeInBase` ciPieceLength ti
236-- 237--
237type Layout = [(FilePath, Int)] 238type Layout = [(FilePath, Int)]
238 239
239fileInfo :: ContentInfo -> [FileInfo] 240contentLayout :: FilePath -> ContentInfo -> Layout
240fileInfo (SingleFile { ciName = name, ciLength = len, ciMD5sum = md5 }) 241contentLayout rootPath = filesLayout
241 = [FileInfo len md5 [name]] 242 where
242fileInfo (MultiFile { ciFiles = fs }) = fs 243 filesLayout (SingleFile { ciName = name, ciLength = len })
244 = [(rootPath </> BC.unpack name, fromIntegral len)]
245 filesLayout (MultiFile { ciFiles = fs, ciName = dir }) =
246 map (first mkPath . fl) fs
247 where -- TODO use utf8 encoding in name
248 mkPath = ((rootPath </> BC.unpack dir) </>) . joinPath . map BC.unpack
243 249
244fileLayout :: FileInfo -> (FilePath, Int) 250 fl (FileInfo { fiPath = p, fiLength = len }) = (p, fromIntegral len)
245fileLayout (FileInfo { fiLength = len, fiPath = name }) = (path, fromIntegral len)
246 where -- WARN use utf8 encoding in name
247 path = joinPath (map BC.unpack name)
248 251
249 252
250contentLayout :: ContentInfo -> Layout
251contentLayout = map fileLayout . fileInfo
252 253
253 254
254-- | Read and decode a .torrent file. 255-- | Read and decode a .torrent file.