Base85 Class
Definition
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
charschar[]The character array.
offsetintThe starting offset.
countintThe number of characters.
variantBase85VariantThe variant.
styleBaseFormatStylesParsing styles.
Returns
- byte[]
The decoded byte array.
Exceptions
- ArgumentNullException
Thrown when
charsis null.- ArgumentOutOfRangeException
Thrown when
offset,count, orvariantis out of range.- ArgumentException
Thrown when the segment defined by
offsetandcountexceeds the available range ofchars.- 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
charsReadOnlySpan<char>The character span.
variantBase85VariantThe variant.
styleBaseFormatStylesParsing styles.
Returns
- byte[]
The decoded byte array. Returns Empty<T>() for empty input.
Exceptions
- ArgumentOutOfRangeException
Thrown when
variantis 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
sstringThe Base85 input.
variantBase85VariantThe variant.
styleBaseFormatStylesParsing styles. Only IgnoreWhitespace has effect.
Returns
- byte[]
The decoded byte array.
Exceptions
- ArgumentNullException
Thrown when
sis null.- ArgumentOutOfRangeException
Thrown when
variantis 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
sourceReadOnlySpan<byte>The UTF-8 Base85 source.
destinationSpan<byte>The destination byte span.
bytesConsumedintWhen this method returns, contains the number of source bytes consumed.
bytesWrittenintWhen this method returns, contains the number of bytes written.
variantBase85VariantThe variant.
stylesBaseFormatStylesParsing 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
sourceReadOnlySpan<char>The Git-padded Base85 input.
decodedLengthintThe number of bytes the original payload contained.
stylesBaseFormatStylesParsing styles. Only IgnoreWhitespace has effect.
Returns
- byte[]
The decoded byte array of length
decodedLength.
Exceptions
- ArgumentOutOfRangeException
Thrown when
decodedLengthis negative.- ArgumentException
Thrown when the retained input length is not a multiple of five characters, or when
decodedLengthis 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
sourceReadOnlySpan<char>The Base85 characters (20 chars for Ascii85 or Z85; additional 4 with delimiters).
variantBase85VariantThe Base85 variant.
stylesBaseFormatStylesParsing styles.
Returns
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
bytesbyte[]The bytes to encode.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting 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
bytesis null.- ArgumentOutOfRangeException
Thrown when
variantis undefined.- ArgumentException
Thrown when
variantis 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
bytesbyte[]The byte array.
offsetintThe starting offset.
countintThe number of bytes to encode.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).
Returns
- string
A Base85 string.
Exceptions
- ArgumentNullException
Thrown when
bytesis null.- ArgumentOutOfRangeException
Thrown when
offset,count, orvariantis out of range.- ArgumentException
Thrown when the segment defined by
offsetandcountexceeds the available range ofbytes, 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
valueGuidThe Guid to encode.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting 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
bytesReadOnlySpan<byte>The bytes to encode.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting 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
variantis undefined.- ArgumentException
Thrown when
variantis 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
sourceReadOnlySpan<byte>The bytes to encode.
writerIBufferWriter<char>The buffer writer that receives the encoded characters.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).
Returns
- int
The number of characters written.
Exceptions
- ArgumentNullException
Thrown when
writeris null.- ArgumentOutOfRangeException
Thrown when
variantis undefined.- ArgumentException
Thrown when
variantis 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
bytesReadOnlySpan<byte>The bytes to encode.
destinationSpan<char>The destination span. Must be at least GetMaxEncodedLength(int, Base85Variant, BaseFormattingOptions) characters in size.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).
Returns
- int
The number of characters written.
Exceptions
- ArgumentException
Thrown when
destinationis too small or, for Z85, when the byte count is not a multiple of four.- ArgumentOutOfRangeException
Thrown when
variantis 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
sourceReadOnlySpan<byte>The bytes to encode.
Returns
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
sourceReadOnlySpan<byte>The bytes to encode.
variantBase85VariantThe variant.
Returns
- byte[]
The UTF-8 encoded Base85 bytes.
Exceptions
- ArgumentOutOfRangeException
Thrown when
variantis undefined.- ArgumentException
Thrown when
variantis 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
sourceReadOnlySpan<byte>The bytes to encode.
writerIBufferWriter<byte>The buffer writer that receives the UTF-8 bytes.
variantBase85VariantThe Base85 variant.
Returns
- int
The number of UTF-8 bytes written.
Exceptions
- ArgumentNullException
Thrown when
writeris null.- ArgumentOutOfRangeException
Thrown when
variantis undefined.- ArgumentException
Thrown when
variantis 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
utf8SourceReadOnlySpan<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
utf8SourceReadOnlySpan<byte>The UTF-8 Ascii85 source.
destinationSpan<byte>The destination byte span.
bytesConsumedintWhen this method returns, contains the number of source bytes consumed.
bytesWrittenintWhen 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
charsReadOnlySpan<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
sourceReadOnlySpan<char>The character span.
destinationSpan<byte>The destination byte span.
charsConsumedintWhen this method returns, contains the number of characters consumed.
bytesWrittenintWhen 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
sstringThe Ascii85 input.
Returns
- byte[]
The decoded byte array.
Exceptions
- ArgumentNullException
Thrown when
sis 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
sourceReadOnlySpan<byte>The input bytes.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting 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
variantis undefined.- ArgumentException
Thrown when
variantis 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
byteCountintThe input byte count. Must be non-negative.
Returns
- int
The encoded character count:
((byteCount + 3) / 4) * 5.
Exceptions
- ArgumentOutOfRangeException
Thrown when
byteCountis 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
charCountintThe input character count. Must be non-negative.
Returns
- int
The worst-case decoded byte count.
Exceptions
- ArgumentOutOfRangeException
Thrown when
charCountis 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
byteCountintThe input byte count. Must be non-negative.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting 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
byteCountis 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
valuecharThe character to test.
variantBase85VariantThe variant.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
variantis 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
sourceReadOnlySpan<char>The input characters.
variantBase85VariantThe variant.
stylesBaseFormatStylesParsing styles. IgnoreWhitespace permits whitespace in the input; AllowPrefix permits the optional Adobe Ascii85
<~/~>delimiter pair (Ascii85 only).
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
variantis undefined.
ToBase85String(byte[])
Encodes inArray into an Adobe Ascii85 string.
public static string ToBase85String(byte[] inArray)
Parameters
inArraybyte[]The byte array to encode.
Returns
- string
An Ascii85 string.
Exceptions
- ArgumentNullException
Thrown when
inArrayis 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
inArraybyte[]The byte array.
offsetintThe starting offset.
lengthintThe number of bytes to encode.
Returns
- string
An Ascii85 string.
Exceptions
- ArgumentNullException
Thrown when
inArrayis null.- ArgumentOutOfRangeException
Thrown when
offsetorlengthis out of range.- ArgumentException
Thrown when the segment defined by
offsetandlengthexceeds the available range ofinArray.
ToBase85String(ReadOnlySpan<byte>)
Encodes bytes into an Ascii85 string.
public static string ToBase85String(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<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
charsReadOnlySpan<char>The Base85 character span.
destinationSpan<byte>The destination byte span.
bytesWrittenintWhen this method returns, contains the number of bytes written.
variantBase85VariantThe variant.
styleBaseFormatStylesParsing styles.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
variantis 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
sourceReadOnlySpan<char>The Git-padded Base85 input.
decodedLengthintThe number of bytes the original payload contained.
destinationSpan<byte>The destination byte span.
bytesWrittenintWhen this method returns, contains the number of bytes written.
stylesBaseFormatStylesParsing styles. Only IgnoreWhitespace has effect.
Returns
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
sourceReadOnlySpan<char>The Base85 characters.
valueGuidWhen this method returns, contains the decoded Guid or Empty.
variantBase85VariantThe Base85 variant.
stylesBaseFormatStylesParsing styles.
Returns
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
bytesReadOnlySpan<byte>The bytes to encode.
destinationSpan<char>The destination span.
charsWrittenintWhen this method returns, contains the number of characters written.
variantBase85VariantThe Base85 variant.
optionsBaseFormattingOptionsFormatting options. See Encode(ReadOnlySpan<byte>, Base85Variant, BaseFormattingOptions).
Returns
Exceptions
- ArgumentException
Thrown for Z85 when the byte count is not a multiple of four.
- ArgumentOutOfRangeException
Thrown when
variantis 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
sourceReadOnlySpan<byte>The bytes to encode.
destinationSpan<char>The destination span.
charsWrittenintWhen this method returns, contains the number of characters written.
Returns
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
sourceReadOnlySpan<byte>The bytes to encode.
destinationSpan<byte>The destination UTF-8 byte span.
bytesWrittenintWhen this method returns, contains the number of bytes written.
variantBase85VariantThe variant.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
variantis undefined.- ArgumentException
Thrown when
variantis 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
sourceReadOnlySpan<byte>The bytes to encode.
utf8DestinationSpan<byte>The UTF-8 destination span.
bytesWrittenintWhen this method returns, contains the number of bytes written.
Returns
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
sourceReadOnlySpan<byte>The bytes to encode.
destinationSpan<char>The destination span.
charsWrittenintWhen this method returns, contains the number of characters written.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |