FileStorage

The set of files in a torrent and the geometry that ties them to pieces: port of libtorrent's file_storage. For a single-file torrent there is exactly one entry whose path is the torrent name.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Blocks per piece for the v2 merkle layout (pieceLength / 16KiB, at least 1).

Link copied to clipboard

Files in their canonical order.

Link copied to clipboard

True for a single-file torrent.

Link copied to clipboard

The torrent name: the file name for single-file, the root directory for multi-file.

Link copied to clipboard
Link copied to clipboard

Number of pieces covering the concatenated data.

Link copied to clipboard

Piece size in bytes (a power of two for well-formed torrents).

Link copied to clipboard

Sum of all file sizes.

Functions

Link copied to clipboard
fun fileForPiece(piece: Int): Int

The file index that owns the byte range at the start of piece piece: port of file_storage::file_index_at_piece. For v2/hybrid (piece-aligned) torrents this is the file the whole piece belongs to. Returns -1 for an out-of-range piece or when there are no files. Pad files are included (they occupy real pieces in the layout).

Link copied to clipboard
fun fileIndexAtPiece(piece: Int): Int

Alias matching libtorrent's file_index_at_piece.

Link copied to clipboard
fun fileNumPieces(fileIndex: Int): Int

Number of v2 pieces in file fileIndex: port of file_storage::file_num_pieces. Equivalent to numPiecesInFile but computed from the file size alone (independent of the concatenated-stream offset), matching how v2 per-file trees are laid out.

Link copied to clipboard
fun firstPieceOf(fileIndex: Int): Int

The piece index this file starts on (file_offset / piece_length).

Link copied to clipboard
fun isPadFile(fileIndex: Int): Boolean

True if file fileIndex is a BEP-47 padding file (not downloadable content).

Link copied to clipboard

True if the geometry is usable (positive piece length).

Link copied to clipboard
fun numBlocksInFile(fileIndex: Int): Int

Number of 16 KiB merkle leaf blocks in file fileIndex: port of file_storage::file_num_blocks. Rounds the file size up to whole blocks.

Link copied to clipboard
fun numPiecesInFile(fileIndex: Int): Int

Number of pieces (partial pieces counted) that file fileIndex spans.

Link copied to clipboard
fun pieceInFileToFilePiece(fileIndex: Int, pieceInFile: Int): Int

The piece-layer offset of file fileIndex's piece pieceInFile within that file's tree.

Link copied to clipboard
fun pieceRangeForFile(fileIndex: Int): IntRange

The piece range covering file fileIndex, inclusive at both ends. The range runs from the piece holding the file's first byte to the piece holding its last byte. This is analogous to file_storage::file_piece_range. A zero-length file returns IntRange.EMPTY.

Link copied to clipboard
fun pieceSize(index: Int): Int

Size of piece index; the final piece is usually shorter than pieceLength.