src/b64.bend checks
raw source on the hub · import bendonnect-rpc@0.1.0.0/src/b64.bend as B64
Base64 (RFC 4648 sections 4 and 5) over Bytes. Pure. Encoders return String (ASCII); decode takes a String and accepts either alphabet, padded or not. Built on Bytes.to_base64 / Bytes.from_base64.
2 imports
import Base import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
Definitions
def strip_pad.pick source · line 8 · raw
@hit:Bool -> @h:Char -> @t:String -> @rest:(@_:Unit -> String) -> String
Drops the leading '=' run of a reversed string (i.e. trailing pad of the original).
def strip_pad.rev source · line 15 · raw
@s:String -> String
def swap2 source · line 23 · raw
@s:String -> @+a1:U32 -> @+b1:U32 -> @+a2:U32 -> @+b2:U32 -> String
Maps char a1 to b1 and a2 to b2, leaving other chars alone.
def encode_std source · line 31 · raw
@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> String
Standard alphabet ('+', '/') with '=' padding.
def encode_std_raw source · line 35 · raw
@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> String
Standard alphabet, no padding.
def encode_url_raw source · line 39 · raw
@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> String
URL-safe alphabet ('-', '_'), no padding.
def has_pad source · line 42 · raw
@s:String -> Bool
def decode.padded source · line 49 · raw
@+s:String -> @+m:U32 -> Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>
def decode.norm source · line 55 · raw
@+s:String -> @+n:U32 -> Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>
def decode source · line 60 · raw
@+s:String -> Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>
Either alphabet, padded or unpadded. None on any invalid input (bad char, bad padding, impossible length).