Portable RFC 4648 Base64 and WHATWG forgiving decoding ported from base64-simd
///|
test "standard padded Base64" {
assert_eq(
@base64.standard.encode_to_string(b"hello world"),
"aGVsbG8gd29ybGQ=",
)
assert_eq(@base64.standard.decode_string("aGVsbG8gd29ybGQ="), b"hello world")
}///|
test "URL-safe and WHATWG forgiving decoding" {
assert_eq(@base64.url_safe_no_pad.encode_to_string(b"\xfb\xff"), "-_8")
assert_eq(@base64.url_safe_no_pad.decode_string("-_8"), b"\xfb\xff")
assert_eq(@base64.forgiving_decode_string(" Z h = = \n"), b"f")
}fn Base64::decode_append(self : Base64, input : BytesView, output : Buffer, simd? : Bool) -> Unit raise Base64Errorfn Base64::decode_inplace(self : Base64, data : FixedArray[Byte], length? : Int, simd? : Bool) -> Int raise Base64Errorfn Base64::decode_into(self : Base64, input : BytesView, output : FixedArray[Byte], offset? : Int, simd? : Bool) -> Int raise Base64Errorfn Base64::decode_string(self : Base64, input : StringView, simd? : Bool) -> Bytes raise Base64Errortest {
assert_eq(@base64.url_safe_no_pad.decode_string("-_8"), b"\xfb\xff")
}fn Base64::encode_append(self : Base64, input : BytesView, output : StringBuilder, simd? : Bool) -> Unitfn Base64::encode_into(self : Base64, input : BytesView, output : FixedArray[Byte], offset? : Int, simd? : Bool) -> Int raise Base64Errortest {
assert_eq(
@base64.standard.encode_to_string(b"hello world"),
"aGVsbG8gd29ybGQ=",
)
}fn forgiving_decode_inplace(data : FixedArray[Byte], length? : Int, simd? : Bool) -> Int raise Base64Errorfn forgiving_decode_into(input : BytesView, output : FixedArray[Byte], offset? : Int, simd? : Bool) -> Int raise Base64ErrorInstall
Download zipPortable RFC 4648 Base64 and WHATWG forgiving decoding ported from base64-simd