// //------------------ DOK FILE -------------------------------------------------- +Header core.util.base64 =pkg core.util.base64 =title core.util.base64 =short base64 representation =desc This library contains functions to manipulate base64 representations. // // //------------------ PROTO ----------------------------------------------------- b64FromUrl +Proto b64FromUrl =type fun Str -> Str =mode function =pkg core.util.base64 =impl mcy =link =desc This function replaces "-" by "+", "_" by "/", and it adds "=" so that the resulting length is a multiple of 4. It returns nil when the length modulo 4 is 1, as it should never happen. > b64Decode ("SGVsbG8gd29ybGQ") >-> Str: nil > b64Decode (b64FromUrl ("SGVsbG8gd29ybGQ")) >-> Str: "Hello world" It is the opposite of [[urlFromB64]]. It is used when you are sending base64 values in an url, as "+", "/" and "=" could bring confusion. // +arg src =type Str =desc A string // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- urlFromB64 +Proto urlFromB64 =type fun Str -> Str =mode function =pkg core.util.base64 =impl mcy =link =desc This function replaces "+" by "-", "/" by "_", and it removes "=". > urlFromB64 (b64Encode ("Hello world")) >-> Str: "SGVsbG8gd29ybGQ" It is the opposite of [[b64FromUrl]]. It is used when you are sending base64 values in an url, as "+", "/" and "=" could bring confusion. // +arg src =type Str =desc A string // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- b64Decode +Proto b64Decode =type fun Str -> Str =mode function =pkg core.util.base64 =impl mcy =link =desc This function decodes a base64 encoded string. It returns nil when the supplied value is not a base64 representation. > b64Decode ("SGVsbG8gd29ybGQ=") >-> Str: "Hello world" // +arg src =type Str =desc A base64 representation // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- b64Encode +Proto b64Encode =type fun Str -> Str =mode function =pkg core.util.base64 =impl mcy =link =desc This function returns the base64 representation of src. > b64Encode ("Hello world") >-> Str: "SGVsbG8gd29ybGQ=" // +arg src =type Str =desc A string // +arg result =type Str =desc A base64 representation