TorrentFile Class

public sealed class TorrentFile

No documentation is available.

Constructors

NameDescription
TorrentFile()

TorrentFile()

TorrentFile.cs
public TorrentFile()

No documentation is available.

Properties

NameDescription
AdditionalKeysThe keys of the root dictionary this model does not represent. They are written back as they are.
Announce
AnnounceList
Comment
CreatedBy
CreationDate
EncodingThe 'encoding' key naming the code page the text fields are written with.
HttpSeedsWeb seed URLs from the 'httpseeds' key (BEP 17).
InfoThe metainfo dictionary. Replacing it discards the parsed bytes, so the info-hash is recomputed from the model.
NodesDHT bootstrap nodes from the 'nodes' key (BEP 5).
PieceLayersThe BitTorrent v2 'piece layers' key (BEP 52): the piece hashes of each file larger than a piece.
Publisher
PublisherUrlThe 'publisher-url' key. Kept as text because the metainfo value is not guaranteed to be a well-formed URI.
UrlListWeb seed URLs from the 'url-list' key (BEP 19).

AdditionalKeys

TorrentFile.cs

The keys of the root dictionary this model does not represent. They are written back as they are.

public IDictionary<BencodeString, BencodeValue> AdditionalKeys { get; }
public string? Announce { get; set; }

Property value

string?

No documentation is available.

AnnounceList

TorrentFile.cs
public IReadOnlyList<IReadOnlyList<string>>? AnnounceList { get; set; }

No documentation is available.

public string? Comment { get; set; }

Property value

string?

No documentation is available.

public string? CreatedBy { get; set; }

Property value

string?

No documentation is available.

CreationDate

TorrentFile.cs
public DateTimeOffset? CreationDate { get; set; }

Property value

DateTimeOffset?

No documentation is available.

The 'encoding' key naming the code page the text fields are written with.

public string? Encoding { get; set; }

Property value

string?

Remarks

When it names a known encoding other than UTF-8, such as GBK or windows-1251, the text fields of the torrent are read and written with that encoding. An unknown name is ignored: the text fields are UTF-8.

Web seed URLs from the 'httpseeds' key (BEP 17).

public IReadOnlyList<string>? HttpSeeds { get; set; }

The metainfo dictionary. Replacing it discards the parsed bytes, so the info-hash is recomputed from the model.

public TorrentInfo Info { get; set; }

Property value

TorrentInfo

DHT bootstrap nodes from the 'nodes' key (BEP 5).

public IReadOnlyList<TorrentNode>? Nodes { get; set; }

PieceLayers

TorrentFile.cs

The BitTorrent v2 'piece layers' key (BEP 52): the piece hashes of each file larger than a piece.

public IReadOnlyList<TorrentPieceLayer>? PieceLayers { get; set; }
public string? Publisher { get; set; }

Property value

string?

No documentation is available.

PublisherUrl

TorrentFile.cs

The 'publisher-url' key. Kept as text because the metainfo value is not guaranteed to be a well-formed URI.

public string? PublisherUrl { get; set; }

Property value

string?

Web seed URLs from the 'url-list' key (BEP 19).

public IReadOnlyList<string>? UrlList { get; set; }

Property value

IReadOnlyList<string>?

Remarks

BEP 19 allows a bare string as well as a list; both are read into this list, and it is always written back as a list.

Methods

NameDescription
GetInfoHashSha1()Computes the BitTorrent v1 info-hash.
GetInfoHashSha256()Computes the SHA-256 of the 'info' dictionary, which is the BitTorrent v2 info-hash.
Parse(ReadOnlySpan<byte>)
ParseAsync(PipeReader, CancellationToken)Parses a torrent from a PipeReader, as the data arrives. Complete the reader yourself.
ParseAsync(Stream, CancellationToken)Parses a torrent from a stream, as the data arrives. The stream is left open.
ToUtf8ByteArray(bool)
TryParse(ReadOnlySpan<byte>, TorrentFile?)
WriteToAsync(Stream, bool, CancellationToken)

GetInfoHashSha1()

TorrentFile.cs

Computes the BitTorrent v1 info-hash.

public byte[] GetInfoHashSha1()

Returns

byte[]

Remarks

For a parsed torrent this hashes the exact bytes the 'info' dictionary was read from, so keys this model does not represent still contribute to the hash.

GetInfoHashSha256()

TorrentFile.cs

Computes the SHA-256 of the 'info' dictionary, which is the BitTorrent v2 info-hash.

public byte[] GetInfoHashSha256()

Returns

byte[]

Remarks

For a parsed torrent this hashes the exact bytes the 'info' dictionary was read from, so keys this model does not represent still contribute to the hash.

Parse(ReadOnlySpan<byte>)

TorrentFile.cs
public static TorrentFile Parse(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

Returns

TorrentFile

No documentation is available.

ParseAsync overloads

ParseAsync(PipeReader, CancellationToken)

TorrentFile.cs

Parses a torrent from a PipeReader, as the data arrives. Complete the reader yourself.

net10.0

public static ValueTask<TorrentFile> ParseAsync(PipeReader reader, CancellationToken cancellationToken = default)

net11.0

public static ValueTask<TorrentFile> ParseAsync(PipeReader reader, CancellationToken cancellationToken = default)
Parameters
reader PipeReader
cancellationToken CancellationToken
Returns

ValueTask<TorrentFile>

ParseAsync(Stream, CancellationToken)

TorrentFile.cs

Parses a torrent from a stream, as the data arrives. The stream is left open.

net10.0

public static ValueTask<TorrentFile> ParseAsync(Stream stream, CancellationToken cancellationToken = default)

net11.0

public static ValueTask<TorrentFile> ParseAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
stream Stream
cancellationToken CancellationToken
Returns

ValueTask<TorrentFile>

ToUtf8ByteArray(bool)

TorrentFile.cs
public byte[] ToUtf8ByteArray(bool canonical = true)

Parameters

canonical bool

Returns

byte[]

No documentation is available.

TryParse(ReadOnlySpan<byte>, TorrentFile?)

TorrentFile.cs
public static bool TryParse(ReadOnlySpan<byte> data, out TorrentFile? result)

Parameters

data ReadOnlySpan<byte>
result TorrentFile?

Returns

bool

No documentation is available.

WriteToAsync(Stream, bool, CancellationToken)

TorrentFile.cs

net10.0

public ValueTask WriteToAsync(Stream stream, bool canonical = true, CancellationToken cancellationToken = default)

net11.0

public ValueTask WriteToAsync(Stream stream, bool canonical = true, CancellationToken cancellationToken = default)

Parameters

stream Stream
canonical bool
cancellationToken CancellationToken

Returns

ValueTask

No documentation is available.