bittorrent-0.0.0.3: Bittorrent protocol implementation.

Portabilityportable
Stabilityexperimental
Maintainerpxqr.sta@gmail.com
Safe HaskellNone

Data.Torrent.Layout

Contents

Description

Layout of files in torrent.

Synopsis

File attributes

type FileSize = FileOffsetSource

Size of a file in bytes.

Single file info

data FileInfo a Source

Contain metainfo about one single file.

Constructors

FileInfo 

Fields

fiLength :: !FileSize

Length of the file in bytes.

fiMD5Sum :: !(Maybe BS.ByteString)

32 character long MD5 sum of the file. Used by third-party tools, not by bittorrent protocol itself.

fiName :: !a

One or more string elements that together represent the path and filename. Each element in the list corresponds to either a directory name or (in the case of the last element) the filename. For example, the file:

 "dir1/dir2/file.ext"

would consist of three string elements:

 ["dir1", "dir2", "file.ext"]

Lens

filePath :: forall a a. Lens (FileInfo a) (FileInfo a) a aSource

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.

Constructors

SingleFile 

Fields

liFile :: !(FileInfo BS.ByteString)

Single file info.

MultiFile 

Fields

liFiles :: ![FileInfo [BS.ByteString]]

List of the all files that torrent contains.

liDirName :: !BS.ByteString

The suggested name of the root directory in which to store all the files.

Lens

Predicates

isSingleFile :: LayoutInfo -> BoolSource

Test if this is single file torrent.

isMultiFile :: LayoutInfo -> BoolSource

Test if this is multifile torrent.

Query

suggestedName :: LayoutInfo -> BS.ByteStringSource

Get name of the torrent based on the root path piece.

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.

flatLayoutSource

Arguments

:: 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