Show / Hide Table of Contents

Struct Base64Decoder

Represents base64 decoder suitable for decoding large base64-encoded binary data using streaming approach.

Implements
IResettable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DotNext.Buffers.Text
Assembly: DotNext.dll
Syntax
public struct Base64Decoder : IResettable
Remarks

This type maintains internal state for correct decoding of streaming data. Therefore, it must be passed by reference to any routine. It's not a ref struct to allow construction of high-level decoders in the form of classes. Base64-encoded bytes can be accepted as UTF-8 or Unicode characters. Decoding methods should not be intermixed by the caller code.

Properties

| Edit this page View Source

NeedMoreData

Indicates that the decoder expects additional data to decode.

Declaration
public readonly bool NeedMoreData { get; }
Property Value
Type Description
bool

Methods

| Edit this page View Source

DecodeFromUtf16(ReadOnlySpan<char>, ref BufferWriterSlim<byte>)

Decodes UTF-8 encoded base64 string.

Declaration
public void DecodeFromUtf16(ReadOnlySpan<char> chars, ref BufferWriterSlim<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<char> chars

UTF-8 encoded portion of base64 string.

BufferWriterSlim<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

| Edit this page View Source

DecodeFromUtf16(scoped ReadOnlySpan<char>, MemoryAllocator<byte>?)

Decodes base64 characters.

Declaration
public MemoryOwner<byte> DecodeFromUtf16(scoped ReadOnlySpan<char> chars, MemoryAllocator<byte>? allocator = null)
Parameters
Type Name Description
ReadOnlySpan<char> chars

The span containing base64-encoded bytes.

MemoryAllocator<byte> allocator

The allocator of the result buffer.

Returns
Type Description
MemoryOwner<byte>

A buffer containing decoded bytes.

Exceptions
Type Condition
FormatException

The input base64 string is malformed.

| Edit this page View Source

DecodeFromUtf16(scoped ReadOnlySpan<char>, IBufferWriter<byte>)

Decodes base64 characters.

Declaration
public void DecodeFromUtf16(scoped ReadOnlySpan<char> chars, IBufferWriter<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<char> chars

The span containing base64-encoded bytes.

IBufferWriter<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

| Edit this page View Source

DecodeFromUtf16Async(IAsyncEnumerable<ReadOnlyMemory<char>>, MemoryAllocator<byte>?, CancellationToken)

Decodes a sequence of base64-encoded bytes.

Declaration
public static IAsyncEnumerable<ReadOnlyMemory<byte>> DecodeFromUtf16Async(IAsyncEnumerable<ReadOnlyMemory<char>> chars, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters
Type Name Description
IAsyncEnumerable<ReadOnlyMemory<char>> chars

A sequence of base64-encoded bytes.

MemoryAllocator<byte> allocator

The allocator of the buffer used for decoded bytes.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
IAsyncEnumerable<ReadOnlyMemory<byte>>

A sequence of decoded bytes.

Exceptions
Type Condition
FormatException

The input base64 string is malformed.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

DecodeFromUtf8(ReadOnlySpan<byte>, ref BufferWriterSlim<byte>)

Decodes UTF-8 encoded base64 string.

Declaration
public void DecodeFromUtf8(ReadOnlySpan<byte> chars, ref BufferWriterSlim<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<byte> chars

UTF-8 encoded portion of base64 string.

BufferWriterSlim<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

| Edit this page View Source

DecodeFromUtf8(ReadOnlySpan<byte>, MemoryAllocator<byte>?)

Decoes UTF-8 encoded base64 string.

Declaration
public MemoryOwner<byte> DecodeFromUtf8(ReadOnlySpan<byte> chars, MemoryAllocator<byte>? allocator = null)
Parameters
Type Name Description
ReadOnlySpan<byte> chars

UTF-8 encoded portion of base64 string.

MemoryAllocator<byte> allocator

The allocator of the result buffer.

Returns
Type Description
MemoryOwner<byte>

A buffer containing decoded bytes.

| Edit this page View Source

DecodeFromUtf8(ReadOnlySpan<byte>, IBufferWriter<byte>)

Decodes UTF-8 encoded base64 string.

Declaration
public void DecodeFromUtf8(ReadOnlySpan<byte> chars, IBufferWriter<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<byte> chars

UTF-8 encoded portion of base64 string.

IBufferWriter<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

| Edit this page View Source

DecodeFromUtf8Async(IAsyncEnumerable<ReadOnlyMemory<byte>>, MemoryAllocator<byte>?, CancellationToken)

Decodes a sequence of base64-encoded bytes.

Declaration
public static IAsyncEnumerable<ReadOnlyMemory<byte>> DecodeFromUtf8Async(IAsyncEnumerable<ReadOnlyMemory<byte>> utf8Chars, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters
Type Name Description
IAsyncEnumerable<ReadOnlyMemory<byte>> utf8Chars

A sequence of base64-encoded bytes.

MemoryAllocator<byte> allocator

The allocator of the buffer used for decoded bytes.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
IAsyncEnumerable<ReadOnlyMemory<byte>>

A sequence of decoded bytes.

Exceptions
Type Condition
FormatException

The input base64 string is malformed.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

Reset()

Resets the internal state of the decoder.

Declaration
public void Reset()

Implements

IResettable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾