Base64Encoder
Represents base64 encoder suitable for encoding large binary
data using streaming approach.
using DotNext.Buffers;
using DotNext.Buffers.Text;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace DotNext.Text
{
[StructLayout(LayoutKind.Auto)]
[Obsolete("Use DotNext.Buffers.Text.Base64Encoder type instead.")]
public struct Base64Encoder
{
public const int MaxBufferedDataSize = 2;
public const int MaxCharsToFlush = 4;
public const int MaxInputSize = 1610612733;
private DotNext.Buffers.Text.Base64Encoder encoder;
public bool HasBufferedData {
[IsReadOnly]
get {
return encoder.HasBufferedData;
}
}
public int BufferedDataSize {
[IsReadOnly]
get {
return encoder.BufferedDataSize;
}
}
[IsReadOnly]
public int GetBufferedData(Span<byte> output)
{
return encoder.GetBufferedData(output);
}
public void Reset()
{
encoder.Reset();
}
public void EncodeToChars(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(1)] IBufferWriter<char> output, bool flush = false)
{
encoder.EncodeToChars(bytes, output, flush);
}
public MemoryOwner<char> EncodeToChars(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(2)] MemoryAllocator<char> allocator = null, bool flush = false)
{
return encoder.EncodeToChars(bytes, allocator, flush);
}
[System.Runtime.CompilerServices.NullableContext(1)]
public void EncodeToChars<TConsumer>([System.Runtime.CompilerServices.Nullable(0)] ReadOnlySpan<byte> bytes, TConsumer output, bool flush = false) where TConsumer : IReadOnlySpanConsumer<char>
{
encoder.EncodeToChars(bytes, output, flush);
}
[System.Runtime.CompilerServices.NullableContext(1)]
public void EncodeToChars<[System.Runtime.CompilerServices.Nullable(2)] TArg>([System.Runtime.CompilerServices.Nullable(0)] ReadOnlySpan<byte> bytes, ReadOnlySpanAction<char, TArg> output, TArg arg, bool flush = false)
{
encoder.EncodeToChars(bytes, output, arg, flush);
}
[CLSCompliant(false)]
public void EncodeToChars<[System.Runtime.CompilerServices.Nullable(2)] TArg>(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1
})] IntPtr output, [System.Runtime.CompilerServices.Nullable(1)] TArg arg, bool flush = false)
{
encoder.EncodeToChars(bytes, output, arg, flush);
}
public void EncodeToChars(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(1)] TextWriter output, bool flush = false)
{
encoder.EncodeToChars(bytes, output, flush);
}
public void EncodeToChars(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(1)] StringBuilder output, bool flush = false)
{
encoder.EncodeToChars(bytes, output, flush);
}
[System.Runtime.CompilerServices.NullableContext(2)]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public static IAsyncEnumerable<ReadOnlyMemory<char>> EncodeToCharsAsync([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})] IAsyncEnumerable<ReadOnlyMemory<byte>> bytes, MemoryAllocator<char> allocator = null, CancellationToken token = default(CancellationToken))
{
return DotNext.Buffers.Text.Base64Encoder.EncodeToCharsAsync(bytes, allocator, token);
}
public int Flush(Span<char> output)
{
return encoder.Flush(output);
}
public void EncodeToUtf8(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(1)] IBufferWriter<byte> output, bool flush = false)
{
encoder.EncodeToUtf8(bytes, output, flush);
}
public MemoryOwner<byte> EncodeToUtf8(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(2)] MemoryAllocator<byte> allocator = null, bool flush = false)
{
return encoder.EncodeToUtf8(bytes, allocator, flush);
}
[System.Runtime.CompilerServices.NullableContext(1)]
public void EncodeToUtf8<TConsumer>([System.Runtime.CompilerServices.Nullable(0)] ReadOnlySpan<byte> bytes, TConsumer output, bool flush = false) where TConsumer : IReadOnlySpanConsumer<byte>
{
encoder.EncodeToUtf8(bytes, output, flush);
}
[System.Runtime.CompilerServices.NullableContext(1)]
public void EncodeToUtf8<[System.Runtime.CompilerServices.Nullable(2)] TArg>([System.Runtime.CompilerServices.Nullable(0)] ReadOnlySpan<byte> bytes, ReadOnlySpanAction<byte, TArg> output, TArg arg, bool flush = false)
{
encoder.EncodeToUtf8(bytes, output, arg, flush);
}
[CLSCompliant(false)]
public void EncodeToUtf8<[System.Runtime.CompilerServices.Nullable(2)] TArg>(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1
})] IntPtr output, [System.Runtime.CompilerServices.Nullable(1)] TArg arg, bool flush = false)
{
encoder.EncodeToUtf8(bytes, output, arg, flush);
}
public void EncodeToUtf8(ReadOnlySpan<byte> bytes, [System.Runtime.CompilerServices.Nullable(1)] Stream output, bool flush = false)
{
encoder.EncodeToUtf8(bytes, output, flush);
}
[System.Runtime.CompilerServices.NullableContext(2)]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public static IAsyncEnumerable<ReadOnlyMemory<byte>> EncodeToUtf8Async([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})] IAsyncEnumerable<ReadOnlyMemory<byte>> bytes, MemoryAllocator<byte> allocator = null, CancellationToken token = default(CancellationToken))
{
return DotNext.Buffers.Text.Base64Encoder.EncodeToUtf8Async(bytes, allocator, token);
}
public int Flush(Span<byte> output)
{
return encoder.Flush(output);
}
}
}