Portability | portable |
---|---|
Stability | experimental |
Maintainer | pxqr.sta@gmail.com |
Safe Haskell | None |
Layout of files in torrent.
- type FileOffset = COff
- type FileSize = FileOffset
- data FileInfo a = FileInfo {}
- fileLength :: forall a. Lens' (FileInfo a) FileSize
- filePath :: forall a a. Lens (FileInfo a) (FileInfo a) a a
- fileMD5Sum :: forall a. Lens' (FileInfo a) (Maybe BS.ByteString)
- data LayoutInfo
- = SingleFile {
- liFile :: !(FileInfo BS.ByteString)
- | MultiFile {
- liFiles :: ![FileInfo [BS.ByteString]]
- liDirName :: !BS.ByteString
- = SingleFile {
- singleFile :: Traversal' LayoutInfo (FileInfo BS.ByteString)
- multiFile :: Traversal' LayoutInfo [FileInfo [BS.ByteString]]
- rootDirName :: Traversal' LayoutInfo BS.ByteString
- isSingleFile :: LayoutInfo -> Bool
- isMultiFile :: LayoutInfo -> Bool
- contentLength :: LayoutInfo -> FileSize
- fileCount :: LayoutInfo -> Int
- blockCount :: BlockSize -> LayoutInfo -> Int
- type Layout a = [(FilePath, a)]
- flatLayout :: FilePath -> LayoutInfo -> Layout FileSize
- accumOffsets :: Layout FileSize -> Layout FileOffset
- fileOffset :: FilePath -> Layout FileOffset -> Maybe FileOffset
- getLayoutInfo :: Get LayoutInfo
- putLayoutInfo :: Put LayoutInfo
File attributes
type FileOffset = COff
type FileSize = FileOffsetSource
Size of a file in bytes.
Single file info
Contain metainfo about one single file.
FileInfo | |
|
Lens
fileLength :: forall a. Lens' (FileInfo a) FileSizeSource
fileMD5Sum :: forall a. Lens' (FileInfo a) (Maybe BS.ByteString)Source
File layout
data LayoutInfo Source
Original (found in torrent file) layout info is either:
- Single file with its name.
- Multiple files with its relative file paths.
SingleFile | |
| |
MultiFile | |
|
Lens
Predicates
isSingleFile :: LayoutInfo -> BoolSource
Test if this is single file torrent.
isMultiFile :: LayoutInfo -> BoolSource
Test if this is multifile torrent.
Folds
contentLength :: LayoutInfo -> FileSizeSource
Find sum of sizes of the all torrent files.
fileCount :: LayoutInfo -> IntSource
Get number of all files in torrent.
blockCount :: BlockSize -> LayoutInfo -> IntSource
Find number of blocks of the specified size. If torrent size is not a multiple of block size then the count is rounded up.
Flat file layout
type Layout a = [(FilePath, a)]Source
File layout specifies the order and the size of each file in the storage. Note that order of files is highly important since we coalesce all the files in the given order to get the linear block address space.
:: FilePath | Root path for the all torrent files. |
-> LayoutInfo | Torrent content information. |
-> Layout FileSize | The all file paths prefixed with the given root. |
Extract files layout from torrent info with the given root path.
accumOffsets :: Layout FileSize -> Layout FileOffsetSource
Calculate offset of each file based on its length, incrementally.
fileOffset :: FilePath -> Layout FileOffset -> Maybe FileOffsetSource
Gives global offset of a content file for a given full path.
Internal
getLayoutInfo :: Get LayoutInfoSource
putLayoutInfo :: Put LayoutInfoSource