BencodeValueExtensions Class

public static class BencodeValueExtensions

No documentation is available.

Methods

NameDescription
ToUtf8ByteArray(BencodeValue, bool)Encodes a bencode value to a UTF-8 byte array.
WriteToAsync(BencodeValue, Stream, bool, CancellationToken)

ToUtf8ByteArray(BencodeValue, bool)

BencodeValueExtensions.cs

Encodes a bencode value to a UTF-8 byte array.

public static byte[] ToUtf8ByteArray(this BencodeValue value, bool canonical = true)

Parameters

value BencodeValue
The value to encode.
canonical bool
true to sort dictionary keys by their byte order (canonical bencode); false to keep dictionary insertion order.

Returns

byte[]

Remarks

Canonical ordering is important when deterministic output is required. Since dictionary order changes the encoded bytes, sorting keys ensures equivalent dictionaries produce the same serialized value, which is required for stable hashes (for example torrent info-hashes) and cross-implementation consistency.

WriteToAsync(BencodeValue, Stream, bool, CancellationToken)

BencodeValueExtensions.cs

net10.0

public static ValueTask WriteToAsync(this BencodeValue value, Stream stream, bool canonical = true, CancellationToken cancellationToken = default)

net11.0

public static ValueTask WriteToAsync(this BencodeValue value, Stream stream, bool canonical = true, CancellationToken cancellationToken = default)

Parameters

value BencodeValue
stream Stream
canonical bool
cancellationToken CancellationToken

Returns

ValueTask

No documentation is available.