b64.bend checks
raw source on the hub · import 0xd6fc55bf65b187fec4175f80d08c165a/b64.bend as B64
UTF-8 and base64 (RFC 4648), both ways; from bend-smtp.
1 import
import Base
Definitions
def Word.pick source · line 4 · raw
@c:Bool -> @a:U32 -> @b:U32 -> U32
def Utf8.cont source · line 14 · raw
@+c:U32 -> @n:Nat -> U32
def Utf8.size source · line 18 · raw
@+c:U32 -> Nat
How many bytes a code point takes.
def Utf8.put.k source · line 23 · raw
@k:Nat -> @+c:U32 -> @rest:List<&2, U32> -> List<&2, U32>
def Utf8.put source · line 37 · raw
@+c:U32 -> @rest:List<&2, U32> -> List<&2, U32>
One code point's bytes, put in front of rest.
def Utf8.bytes source · line 40 · raw
@s:String -> List<&2, U32>
def B64.ch source · line 51 · raw
@+i:U32 -> Char
The base64 digit for 0..63.
def B64.at source · line 57 · raw
@+x:U32 -> @n:Nat -> Char
def B64.quad source · line 61 · raw
@+x:U32 -> @pad:Nat -> @rest:String -> String
A group of 4 digits, the last pad of them "=".
def B64.word source · line 72 · raw
@+a:U32 -> @+b:U32 -> @+c:U32 -> U32
def B64.onto source · line 75 · raw
@acc:String -> @tail:String -> String
def B64.quad.rev source · line 83 · raw
@+x:U32 -> @pad:Nat -> @acc:String -> String
The 4 digits of a group, reversed, on acc; pad of them "=".
def B64.brk source · line 94 · raw
@full:Bool -> @acc:String -> String
A CRLF (reversed) before the group when wrap groups fill the line.
def B64.go source · line 104 · raw
@bs:List<&2, U32> -> @+k:U32 -> @+wrap:U32 -> @acc:String -> @tail:String -> String
The digits of bs, in front of tail; k groups are on the current line,
and a line takes wrap groups (0: one line). acc holds the digits so
far, reversed: one tail call per group, then one pass onto the tail.
def B64.encode source · line 120 · raw
@bs:List<&2, U32> -> String
def B64.lines source · line 125 · raw
@bs:List<&2, U32> -> @tail:String -> String
Base64 in lines of 76 digits (19 groups), as MIME bodies need, then tail.
def B64.text source · line 128 · raw
@s:String -> String
def B64.val source · line 135 · raw
@+c:U32 -> U32
A base64 digit's value, or 64 for anything else.
def B64.keep source · line 141 · raw
@ok:Bool -> @v:U32 -> @rest:List<&2, U32> -> List<&2, U32>
def B64.vals source · line 148 · raw
@s:String -> List<&2, U32>
def B64.byte source · line 156 · raw
@+x:U32 -> @n:Nat -> U32
def B64.group source · line 159 · raw
@+a:U32 -> @+b:U32 -> @+c:U32 -> @+d:U32 -> U32
def B64.bytes source · line 162 · raw
@vs:List<&2, U32> -> List<&2, U32>
def B64.decode source · line 176 · raw
@s:String -> List<&2, U32>
The bytes of base64 text; padding and anything off the alphabet skipped.
def B64.ascii source · line 180 · raw
@bs:List<&2, U32> -> String
Bytes as text: ASCII as is, any other byte as "?" (for error messages).