Table of Contents

Base85 Class

Definition

Namespace
Bodu.Text.Encoding
Assembly
Bodu.Text.Encoding.dll
Package
Bodu.Text.Encoding 1.0.0
Source
Base85.BclAliases.cs

Provides Base85 encoding and decoding of binary data using the Adobe Ascii85, ZeroMQ Z85, or Git-style alphabets.

public static class Base85
Inheritance
Base85
Inherited Members

Examples

byte[] data = "hello world"u8.ToArray();

// Adobe Ascii85 (default) - the form used by PostScript and PDF, with the 'z' shortcut for all-zero groups.
string ascii85 = Base85.Encode(data);

// Wrap the output in the Adobe <~ ... ~> delimiter pair.
string delimited = Base85.Encode(data, BaseFormattingOptions.IncludePrefix);

// ZeroMQ Z85 - shell-safe alphabet; the input must be a multiple of four bytes.
byte[] padded = "hello wor"u8.ToArray();    // 9 bytes - pad to 12 before encoding
string z85    = Base85.Encode(padded.AsSpan(0, 8), Base85Variant.Z85);

// Round-trip.
byte[] roundtrip = Base85.Decode(ascii85);

Remarks

Base85 packs four input bytes into a 32-bit unsigned integer, then divides by 85 four times to emit five output characters per four-byte group - a payload expansion of 25 %, compared to Base64's 33 % and Base16's 100 %.

The Adobe Ascii85 variant recognises the character z as a shortcut for four zero bytes and permits partial trailing groups of one, two, or three bytes (output grows by one character per byte plus one). The Z85 variant requires the input to be a whole multiple of four bytes and does not use any shortcut. The GitCompact variant uses the Git binary-patch alphabet with the same compact partial-tail behaviour as Ascii85 but without the z shortcut or the Adobe delimiters; it implements only the alphabet and does not parse Git binary patches. The exact Git binary-patch line primitive (always five characters per group, with the decoded length carried out of band) is available through the EncodeGitPadded / DecodeGitPadded helpers.

Base85 has no padding character. The UpperCase, InsertSpacing, InsertLineBreaks, and OmitPadding flags are ignored on the encode side. IncludePrefix is honoured for the Ascii85 variant - when set, the output is wrapped in the Adobe Ascii85 <~ / ~> delimiter pair. The flag is ignored for Z85.

On the decode side, IgnoreWhitespace permits whitespace in the input. AllowPrefix permits an optional <~ / ~> delimiter pair around the Ascii85 payload.

Methods

Decode(char[], int, int, Base85Variant, BaseFormatStyles)

Decodes a portion of a character array.

public static byte[] Decode(char[] chars, int offset, int count, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles style = BaseFormatStyles.None)

Parameters

chars char[]

The character array.

offset int

The starting offset.

count int

The number of characters.

variant Base85Variant

The variant.

style BaseFormatStyles

Parsing styles.

Returns

byte[]

The decoded byte array.

Exceptions

ArgumentNullException

Thrown when chars is null.

ArgumentOutOfRangeException

Thrown when offset, count, or variant is out of range.

ArgumentException

Thrown when the segment defined by offset and count exceeds the available range of chars.

FormatException

Thrown when the input is not valid Base85.

Decode(ReadOnlySpan<char>, Base85Variant, BaseFormatStyles)

Decodes a Base85 character span into a byte array.

public static byte[] Decode(ReadOnlySpan<char> chars, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles style = BaseFormatStyles.None)

Parameters

chars ReadOnlySpan<char>

The character span.

variant Base85Variant

The variant.

style BaseFormatStyles

Parsing styles.

Returns

byte[]

The decoded byte array. Returns Empty<T>() for empty input.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

FormatException

Thrown when the input is not valid Base85.

Decode(string, Base85Variant, BaseFormatStyles)

Decodes a Base85 string into a byte array using the supplied variant.

public static byte[] Decode(string s, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles style = BaseFormatStyles.None)

Parameters

s string

The Base85 input.

variant Base85Variant

The variant.

style BaseFormatStyles

Parsing styles. Only IgnoreWhitespace has effect.

Returns

byte[]

The decoded byte array.

Exceptions

ArgumentNullException

Thrown when s is null.

ArgumentOutOfRangeException

Thrown when variant is undefined.

FormatException

Thrown when the input is not valid Base85 for the chosen variant.

DecodeFromUtf8(ReadOnlySpan<byte>, Span<byte>, out int, out int, Base85Variant, BaseFormatStyles)

Decodes UTF-8 Base85 bytes into a byte span using the OperationStatus return convention.

public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles styles = BaseFormatStyles.None)

Parameters

source ReadOnlySpan<byte>

The UTF-8 Base85 source.

destination Span<byte>

The destination byte span.

bytesConsumed int

When this method returns, contains the number of source bytes consumed.

bytesWritten int

When this method returns, contains the number of bytes written.

variant Base85Variant

The variant.

styles BaseFormatStyles

Parsing styles.

Returns

OperationStatus

An OperationStatus describing the outcome.

Remarks

Base85 decoding is not streamable in a useful way (each group requires exactly five characters), so the decoder treats source as a complete input and does not return NeedMoreData.

DecodeGitPadded(ReadOnlySpan<char>, int, BaseFormatStyles)

Decodes a Git-padded Base85 character span, returning the leading decodedLength bytes.

public static byte[] DecodeGitPadded(ReadOnlySpan<char> source, int decodedLength, BaseFormatStyles styles = BaseFormatStyles.None)

Parameters

source ReadOnlySpan<char>

The Git-padded Base85 input.

decodedLength int

The number of bytes the original payload contained.

styles BaseFormatStyles

Parsing styles. Only IgnoreWhitespace has effect.

Returns

byte[]

The decoded byte array of length decodedLength.

Exceptions

ArgumentOutOfRangeException

Thrown when decodedLength is negative.

ArgumentException

Thrown when the retained input length is not a multiple of five characters, or when decodedLength is inconsistent with the number of encoded groups.

FormatException

Thrown when the input contains a character outside the Git Base85 alphabet or a group overflows a 32-bit value.

DecodeGuid(ReadOnlySpan<char>, Base85Variant, BaseFormatStyles)

Decodes a Base85 representation of a Guid.

public static Guid DecodeGuid(ReadOnlySpan<char> source, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles styles = BaseFormatStyles.None)

Parameters

source ReadOnlySpan<char>

The Base85 characters (20 chars for Ascii85 or Z85; additional 4 with delimiters).

variant Base85Variant

The Base85 variant.

styles BaseFormatStyles

Parsing styles.

Returns

Guid

The decoded Guid.

Exceptions

FormatException

Thrown when the input does not decode to exactly 16 bytes.

Encode(byte[], Base85Variant, BaseFormattingOptions)

Encodes bytes into a Base85 string using the supplied variant and options.

public static string Encode(byte[] bytes, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

bytes byte[]

The bytes to encode.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. When the variant is Ascii85 and IncludePrefix is set, the output is wrapped in the Adobe Ascii85 <~ and ~> delimiters.

Returns

string

A Base85 string.

Exceptions

ArgumentNullException

Thrown when bytes is null.

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the byte count is not a multiple of four.

Encode(byte[], int, int, Base85Variant, BaseFormattingOptions)

Encodes a portion of bytes into a Base85 string.

public static string Encode(byte[] bytes, int offset, int count, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

bytes byte[]

The byte array.

offset int

The starting offset.

count int

The number of bytes to encode.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).

Returns

string

A Base85 string.

Exceptions

ArgumentNullException

Thrown when bytes is null.

ArgumentOutOfRangeException

Thrown when offset, count, or variant is out of range.

ArgumentException

Thrown when the segment defined by offset and count exceeds the available range of bytes, or the Z85 variant receives a byte count not divisible by four.

Encode(Guid, Base85Variant, BaseFormattingOptions)

Encodes the byte representation of value as a Base85 string. 16 bytes encode to exactly 20 characters (Ascii85 or Z85).

public static string Encode(Guid value, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

value Guid

The Guid to encode.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options.

Returns

string

A Base85 string of the GUID bytes (mixed-endian, matching TryWriteBytes(Span<byte>)).

Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions)

Encodes a span of bytes into a Base85 string.

public static string Encode(ReadOnlySpan<byte> bytes, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

bytes ReadOnlySpan<byte>

The bytes to encode.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. When the variant is Ascii85 and IncludePrefix is set, the output is wrapped in the Adobe Ascii85 <~ and ~> delimiters. For Z85 the flag is ignored - Z85 has no standard delimiter convention.

Returns

string

A Base85 string.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the byte count is not a multiple of four.

Encode(ReadOnlySpan<byte>, IBufferWriter<char>, Base85Variant, BaseFormattingOptions)

Encodes source as Base85 characters into writer, suitable for use in pipelines and other IBufferWriter<T>-based scenarios.

public static int Encode(ReadOnlySpan<byte> source, IBufferWriter<char> writer, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

writer IBufferWriter<char>

The buffer writer that receives the encoded characters.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).

Returns

int

The number of characters written.

Exceptions

ArgumentNullException

Thrown when writer is null.

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the source length is not a multiple of four bytes.

Encode(ReadOnlySpan<byte>, Span<char>, Base85Variant, BaseFormattingOptions)

Encodes a span of bytes directly into a destination character span.

public static int Encode(ReadOnlySpan<byte> bytes, Span<char> destination, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

bytes ReadOnlySpan<byte>

The bytes to encode.

destination Span<char>

The destination span. Must be at least GetMaxEncodedLength(int, Base85Variant, BaseFormattingOptions) characters in size.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).

Returns

int

The number of characters written.

Exceptions

ArgumentException

Thrown when destination is too small or, for Z85, when the byte count is not a multiple of four.

ArgumentOutOfRangeException

Thrown when variant is undefined.

EncodeGitPadded(ReadOnlySpan<byte>)

Encodes source using the exact Git binary-patch Base85 primitive, emitting five characters for every one-to-four-byte group.

public static string EncodeGitPadded(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

Returns

string

The Git-padded Base85 string. Returns Empty for empty input.

Remarks

Unlike the compact GitCompact mode used by Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions), this primitive never trims the trailing group: a final remainder of one, two, or three bytes is zero-padded internally and still produces five characters. The output is therefore not self-delimiting - decoding requires the original byte count, which Git carries in its binary-patch line prefix. Use DecodeGitPadded(ReadOnlySpan<char>, int, BaseFormatStyles) with that length to recover the bytes.

EncodeToUtf8(ReadOnlySpan<byte>, Base85Variant)

Encodes source into a UTF-8 Base85 byte array.

public static byte[] EncodeToUtf8(ReadOnlySpan<byte> source, Base85Variant variant = Base85Variant.Ascii85)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

variant Base85Variant

The variant.

Returns

byte[]

The UTF-8 encoded Base85 bytes.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the byte count is not a multiple of four.

EncodeToUtf8(ReadOnlySpan<byte>, IBufferWriter<byte>, Base85Variant)

Encodes source as UTF-8 Base85 bytes into writer, suitable for use in pipelines and other IBufferWriter<T>-based scenarios.

public static int EncodeToUtf8(ReadOnlySpan<byte> source, IBufferWriter<byte> writer, Base85Variant variant = Base85Variant.Ascii85)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

writer IBufferWriter<byte>

The buffer writer that receives the UTF-8 bytes.

variant Base85Variant

The Base85 variant.

Returns

int

The number of UTF-8 bytes written.

Exceptions

ArgumentNullException

Thrown when writer is null.

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the source length is not a multiple of four bytes.

FromBase85String(ReadOnlySpan<byte>)

Decodes UTF-8 Ascii85 bytes into a byte array.

public static byte[] FromBase85String(ReadOnlySpan<byte> utf8Source)

Parameters

utf8Source ReadOnlySpan<byte>

The UTF-8 Ascii85 source.

Returns

byte[]

The decoded byte array.

Exceptions

FormatException

Thrown when the input is not valid Ascii85.

FromBase85String(ReadOnlySpan<byte>, Span<byte>, out int, out int)

Ascii85 decode from a UTF-8 byte span returning OperationStatus.

public static OperationStatus FromBase85String(ReadOnlySpan<byte> utf8Source, Span<byte> destination, out int bytesConsumed, out int bytesWritten)

Parameters

utf8Source ReadOnlySpan<byte>

The UTF-8 Ascii85 source.

destination Span<byte>

The destination byte span.

bytesConsumed int

When this method returns, contains the number of source bytes consumed.

bytesWritten int

When this method returns, contains the number of bytes written.

Returns

OperationStatus

An OperationStatus describing the outcome.

FromBase85String(ReadOnlySpan<char>)

Decodes an Ascii85 character span into a byte array.

public static byte[] FromBase85String(ReadOnlySpan<char> chars)

Parameters

chars ReadOnlySpan<char>

The character span.

Returns

byte[]

The decoded byte array.

Exceptions

FormatException

Thrown when the input is not valid Ascii85.

FromBase85String(ReadOnlySpan<char>, Span<byte>, out int, out int)

Ascii85 decode from a character span returning OperationStatus.

public static OperationStatus FromBase85String(ReadOnlySpan<char> source, Span<byte> destination, out int charsConsumed, out int bytesWritten)

Parameters

source ReadOnlySpan<char>

The character span.

destination Span<byte>

The destination byte span.

charsConsumed int

When this method returns, contains the number of characters consumed.

bytesWritten int

When this method returns, contains the number of bytes written.

Returns

OperationStatus

An OperationStatus describing the outcome.

FromBase85String(string)

Decodes an Ascii85 string into a byte array.

public static byte[] FromBase85String(string s)

Parameters

s string

The Ascii85 input.

Returns

byte[]

The decoded byte array.

Exceptions

ArgumentNullException

Thrown when s is null.

FormatException

Thrown when the input is not valid Ascii85.

GetEncodedLength(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions)

Returns the exact number of characters that Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions) will produce for the supplied data, accounting for the Adobe Ascii85 z shortcut on all-zero groups and the optional Adobe Ascii85 <~ ... ~> delimiter pair.

public static int GetEncodedLength(ReadOnlySpan<byte> source, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

source ReadOnlySpan<byte>

The input bytes.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. IncludePrefix adds four characters for the Ascii85 delimiter pair; other flags are ignored.

Returns

int

The exact encoded character count.

Remarks

For Ascii85 the exact length cannot be computed from byte count alone because four-zero groups collapse to a single z character. Code that needs a buffer size without scanning the data should call GetMaxEncodedLength(int, Base85Variant, BaseFormattingOptions) for the worst-case upper bound.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the source length is not a multiple of four bytes.

GetGitPaddedEncodedLength(int)

Returns the exact number of characters that EncodeGitPadded(ReadOnlySpan<byte>) produces for the supplied byte count.

public static int GetGitPaddedEncodedLength(int byteCount)

Parameters

byteCount int

The input byte count. Must be non-negative.

Returns

int

The encoded character count: ((byteCount + 3) / 4) * 5.

Exceptions

ArgumentOutOfRangeException

Thrown when byteCount is negative.

GetMaxDecodedLength(int)

Returns the maximum number of bytes that decoding charCount characters could produce (worst case, assuming no z shortcuts expand to four zero bytes).

public static int GetMaxDecodedLength(int charCount)

Parameters

charCount int

The input character count. Must be non-negative.

Returns

int

The worst-case decoded byte count.

Exceptions

ArgumentOutOfRangeException

Thrown when charCount is negative.

GetMaxEncodedLength(int, Base85Variant, BaseFormattingOptions)

Returns the maximum number of characters that encoding byteCount bytes could produce (i.e. assuming no Ascii85 z shortcuts are emitted), with optional Adobe Ascii85 delimiters.

public static int GetMaxEncodedLength(int byteCount, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

byteCount int

The input byte count. Must be non-negative.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. IncludePrefix adds four characters for the Ascii85 delimiter pair; other flags are ignored.

Returns

int

The worst-case encoded character count.

Exceptions

ArgumentOutOfRangeException

Thrown when byteCount is negative.

IsBase85Digit(char, Base85Variant)

Indicates whether value is a valid digit for the supplied Base85 variant. The Ascii85 z shortcut is not considered a digit.

public static bool IsBase85Digit(char value, Base85Variant variant = Base85Variant.Ascii85)

Parameters

value char

The character to test.

variant Base85Variant

The variant.

Returns

bool

true when the character belongs to the variant alphabet.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

IsValid(ReadOnlySpan<char>, Base85Variant, BaseFormatStyles)

Indicates whether source is a valid Base85 input under the supplied variant.

public static bool IsValid(ReadOnlySpan<char> source, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles styles = BaseFormatStyles.None)

Parameters

source ReadOnlySpan<char>

The input characters.

variant Base85Variant

The variant.

styles BaseFormatStyles

Parsing styles. IgnoreWhitespace permits whitespace in the input; AllowPrefix permits the optional Adobe Ascii85 <~ / ~> delimiter pair (Ascii85 only).

Returns

bool

true when every retained character is in the variant alphabet or is a recognised shortcut.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

ToBase85String(byte[])

Encodes inArray into an Adobe Ascii85 string.

public static string ToBase85String(byte[] inArray)

Parameters

inArray byte[]

The byte array to encode.

Returns

string

An Ascii85 string.

Exceptions

ArgumentNullException

Thrown when inArray is null.

ToBase85String(byte[], int, int)

Encodes a portion of inArray into an Ascii85 string.

public static string ToBase85String(byte[] inArray, int offset, int length)

Parameters

inArray byte[]

The byte array.

offset int

The starting offset.

length int

The number of bytes to encode.

Returns

string

An Ascii85 string.

Exceptions

ArgumentNullException

Thrown when inArray is null.

ArgumentOutOfRangeException

Thrown when offset or length is out of range.

ArgumentException

Thrown when the segment defined by offset and length exceeds the available range of inArray.

ToBase85String(ReadOnlySpan<byte>)

Encodes bytes into an Ascii85 string.

public static string ToBase85String(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

The bytes.

Returns

string

An Ascii85 string.

TryDecode(ReadOnlySpan<char>, Span<byte>, out int, Base85Variant, BaseFormatStyles)

Attempts to decode Base85 characters into a destination byte span.

public static bool TryDecode(ReadOnlySpan<char> chars, Span<byte> destination, out int bytesWritten, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles style = BaseFormatStyles.None)

Parameters

chars ReadOnlySpan<char>

The Base85 character span.

destination Span<byte>

The destination byte span.

bytesWritten int

When this method returns, contains the number of bytes written.

variant Base85Variant

The variant.

style BaseFormatStyles

Parsing styles.

Returns

bool

true on success; false when the input is malformed or the destination is too small.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

TryDecodeGitPadded(ReadOnlySpan<char>, int, Span<byte>, out int, BaseFormatStyles)

Attempts to decode a Git-padded Base85 character span, returning the leading decodedLength bytes.

public static bool TryDecodeGitPadded(ReadOnlySpan<char> source, int decodedLength, Span<byte> destination, out int bytesWritten, BaseFormatStyles styles = BaseFormatStyles.None)

Parameters

source ReadOnlySpan<char>

The Git-padded Base85 input.

decodedLength int

The number of bytes the original payload contained.

destination Span<byte>

The destination byte span.

bytesWritten int

When this method returns, contains the number of bytes written.

styles BaseFormatStyles

Parsing styles. Only IgnoreWhitespace has effect.

Returns

bool

true on success; false when decodedLength is negative, the input is malformed, the framing is inconsistent, or the destination is too small.

TryDecodeGuid(ReadOnlySpan<char>, out Guid, Base85Variant, BaseFormatStyles)

Attempts to decode a Base85 representation of a Guid.

public static bool TryDecodeGuid(ReadOnlySpan<char> source, out Guid value, Base85Variant variant = Base85Variant.Ascii85, BaseFormatStyles styles = BaseFormatStyles.None)

Parameters

source ReadOnlySpan<char>

The Base85 characters.

value Guid

When this method returns, contains the decoded Guid or Empty.

variant Base85Variant

The Base85 variant.

styles BaseFormatStyles

Parsing styles.

Returns

bool

true when decoding succeeds; otherwise false.

TryEncode(ReadOnlySpan<byte>, Span<char>, out int, Base85Variant, BaseFormattingOptions)

Attempts to encode a span of bytes into a destination character span.

public static bool TryEncode(ReadOnlySpan<byte> bytes, Span<char> destination, out int charsWritten, Base85Variant variant = Base85Variant.Ascii85, BaseFormattingOptions options = BaseFormattingOptions.None)

Parameters

bytes ReadOnlySpan<byte>

The bytes to encode.

destination Span<char>

The destination span.

charsWritten int

When this method returns, contains the number of characters written.

variant Base85Variant

The Base85 variant.

options BaseFormattingOptions

Formatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).

Returns

bool

true when the destination is large enough; otherwise false.

Exceptions

ArgumentException

Thrown for Z85 when the byte count is not a multiple of four.

ArgumentOutOfRangeException

Thrown when variant is undefined.

TryEncodeGitPadded(ReadOnlySpan<byte>, Span<char>, out int)

Attempts to encode source using the Git binary-patch Base85 primitive into a destination character span.

public static bool TryEncodeGitPadded(ReadOnlySpan<byte> source, Span<char> destination, out int charsWritten)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

destination Span<char>

The destination span.

charsWritten int

When this method returns, contains the number of characters written.

Returns

bool

true when the destination is large enough; otherwise false.

TryEncodeToUtf8(ReadOnlySpan<byte>, Span<byte>, out int, Base85Variant)

Attempts to encode source as UTF-8 Base85 bytes into destination.

public static bool TryEncodeToUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten, Base85Variant variant = Base85Variant.Ascii85)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

destination Span<byte>

The destination UTF-8 byte span.

bytesWritten int

When this method returns, contains the number of bytes written.

variant Base85Variant

The variant.

Returns

bool

true on success; false when the destination is too small.

Exceptions

ArgumentOutOfRangeException

Thrown when variant is undefined.

ArgumentException

Thrown when variant is Z85 and the byte count is not a multiple of four.

TryToBase85String(ReadOnlySpan<byte>, Span<byte>, out int)

Attempts to encode source as Ascii85 UTF-8 bytes into utf8Destination.

public static bool TryToBase85String(ReadOnlySpan<byte> source, Span<byte> utf8Destination, out int bytesWritten)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

utf8Destination Span<byte>

The UTF-8 destination span.

bytesWritten int

When this method returns, contains the number of bytes written.

Returns

bool

true on success; false when the destination is too small.

TryToBase85String(ReadOnlySpan<byte>, Span<char>, out int)

Attempts to encode source into destination using Ascii85.

public static bool TryToBase85String(ReadOnlySpan<byte> source, Span<char> destination, out int charsWritten)

Parameters

source ReadOnlySpan<byte>

The bytes to encode.

destination Span<char>

The destination span.

charsWritten int

When this method returns, contains the number of characters written.

Returns

bool

true on success; false when the destination is too small.

Applies to

ProductVersions
.NET8, 10