-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiles.hs
More file actions
28 lines (21 loc) · 754 Bytes
/
Files.hs
File metadata and controls
28 lines (21 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Files where
import HTorrentPrelude
import MetaInfo
import Data.Interval
import Data.Isometry
data FileChunk = FileChunk {
_chunkPath :: String,
_chunkRange :: Interval }
$(makeLenses ''FileChunk)
instance Isometry FileChunk where
len = views chunkRange len
restrictLower l = chunkRange %~ restrictLower l
restrictUpper u = chunkRange %~ restrictUpper u
fileChunk :: File -> FileChunk
fileChunk (File l p) = FileChunk p (Interval 0 (l - 1))
fileMap :: [File] -> Piecewise FileChunk
fileMap = fromIsometries . map fileChunk
initFileMap :: Info -> Piecewise FileChunk
initFileMap info = case _file info of
Left size -> fileMap [File size (info ^. name)]
Right files -> fileMap files