Base64Encoding
Namespace: SnowBank.Text · class
Helper type for using the Base62 encoding
Methods
DecodeBuffer
static byte[] DecodeBuffer(ReadOnlySpan<char> encoded, bool padded = true, bool urlSafe = false)
Decodes a Base64 text literal into a byte array
encoded— Base64 text to decodepadded— Set totrueif the encoding used paddingurlSafe— Set totrueif the original used the "web safe" character map (used '-' and '_' instead of '+' and '/')
Returns: Decoded byte array
static Slice DecodeBuffer(ReadOnlySpan<char> encoded, ref byte[] buffer, bool padded = true, bool urlSafe = false)
Decodes a Base64 text literal into a byte buffer
encoded— Base64 text to decodebuffer— Destination buffer. Ifnullor two small, will be replaced with another buffer with sufficient capacitypadded— Set totrueif the encoding used paddingurlSafe— Set totrueif the original used the "web safe" character map (used '-' and '_' instead of '+' and '/')
Returns: Decoded byte buffer, which uses buffer as the backing store
EncodeBuffer
static string EncodeBuffer(ReadOnlySpan<byte> buffer, bool padded = true, bool urlSafe = false)
EncodeBufferUnsafe
static string EncodeBufferUnsafe(ReadOnlySpan<byte> source, bool padded = true, bool urlSafe = false)
EncodeTo
static void EncodeTo(TextWriter output, Slice source, bool padded = true, bool urlSafe = false)
Encodes a byte buffer into Base64 and writes the output into a TextWriter
output— Destination where to write the encoded Base64 textsource— Source buffer with the bytes to encodepadded— Iftrue, pad the input buffer to have the length be a multiple of 3 bytesurlSafe— Iftrue, use the "web safe" character map (replaces '+' and '/' with '-' and '_')
static void EncodeTo(TextWriter output, ReadOnlySpan<byte> source, bool padded = true, bool urlSafe = false)
Encodes a byte buffer into Base64 and writes the output into a TextWriter
output— Destination where to write the encoded Base64 textsource— Source buffer with the bytes to encodepadded— Iftrue, pad the input buffer to have the length be a multiple of 3 bytesurlSafe— Iftrue, use the "web safe" character map (replaces '+' and '/' with '-' and '_')
static void EncodeTo(ref ValueStringWriter output, ReadOnlySpan<byte> source, bool padded = true, bool urlSafe = false)
Encodes a byte buffer into Base64 and appends the output into a ValueStringWriter
output— Destination where to write the encoded Base64 textsource— Source buffer with the bytes to encodepadded— Iftrue, pad the input buffer to have the length be a multiple of 3 bytesurlSafe— Iftrue, use the "web safe" character map (replaces '+' and '/' with '-' and '_')
EstimateBytesCount
static int EstimateBytesCount(int length)
FromBase64String
static byte[] FromBase64String(string s)
static byte[] FromBase64String(ReadOnlySpan<char> s)
FromBase64UrlString
static byte[] FromBase64UrlString(string s)
static byte[] FromBase64UrlString(ReadOnlySpan<char> s)
GetBytesCount
static int GetBytesCount(ReadOnlySpan<char> src, char padChar)
Computes the size of a buffer required to decode a Base64 string into bytes
src— Base64 string literal to decodepadChar— Padding character (optional)
GetCharsCount
static int GetCharsCount(int length, bool padded)
Computes the number of characters required to encode byte buffer into Base64
length— Number of bytes in the sourcepadded— Set totrueif padding is required.
Returns: Minimum capacity required for the output character buffer, in order to encode a byte buffer of size length, including the optional padding.
ToBase64String
static string ToBase64String(byte[] buffer)
static string ToBase64String(Slice buffer)
static string ToBase64String(ReadOnlySpan<byte> buffer)
ToBase64UrlString
static string ToBase64UrlString(byte[] buffer)
static string ToBase64UrlString(ReadOnlySpan<byte> buffer)
static string ToBase64UrlString(Slice buffer)