GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

GOLF(2gg) πŸ’…

okay bestie, welcome to the Development section of the GOLF(2gg) manual, and today's main character is encode-base64. she's giving base64 encoding and she's serving it flawlessly ✨


NAME πŸŽ€

encode-base64 β€” it does (base64), that's the whole vibe πŸ’–


PURPOSE πŸ¦‹

Base64 encode. that's it. that's the girl's whole job. and she ate πŸ”₯


SYNTAX πŸ‘‘

encode-base64 <data> to <output data> \
    [ input-length <input length> ]

DESCRIPTION 🌸

so like, encode-base64 will encode the string <data> into a base64 string, and that result goes by <output data>. literally iconic behaviour πŸ’œ

if you use the "input-length" clause, then <input length> is the number of bytes that get encoded. no "input-length" clause? then the entirety of <data> gets encoded, periodt. 🫢

the result lives in <output data> β€” that's the "to" clause, she's the destination bestie, the final boss, the main character's dressing room πŸŽ€

now why do we even care about base64? because base64-encoded strings are often used where binary data needs to be in a format that complies with certain text-based protocols. think: attaching documents in email πŸ“§, or embedding binary documents (like "JPG" images for example) in web pages with "data:image/jpg;base64..." specified, etc. it's giving ✨glow up for binary data✨


EXAMPLES 🌈

example one: encode, decode, vibe check πŸ’–

an example that encodes a string, decodes, and finally checks if they match:

// Original string, generally this would be binary data in most cases
set-string dt ="  oh well  "

// Encode in base64
encode-base64 dt to out_dt

decode-base64 out_dt to new_dt

if-true dt equal new_dt
    @Success!
else-if
    @Failure!
end-if

she round-trips and she passes the vibe check, no cap πŸ˜­πŸ’…

example two: partial encode, input-length edition 🧚

in the next example, the "input-length" clause is used, and only a partial of the input string is encoded, then later compared to the original:

// Original string, generally this would be binary data in most cases
set-string dt ="  oh well  "

// Encode in base64, encode only 6 bytes
encode-base64 dt input-length 6 to out_dt

decode-base64 out_dt to new_dt

// Get length of decoded string
string-length new_dt to new_len

if-true new_len not-equal 6
    @Failure!
else-if
    @Success!
end-if

if-true dt equal new_dt length new_len
    @Success!
else-if
    @Failure! [<<print-out dt>>] [<<print-out new_dt>>]
end-if

only 6 bytes go in, and the checks are checking, and the lengths are length-ing πŸ¦‹βœ¨


SEE ALSO πŸ”

  • Base64
  • decode-base64
  • encode-base64
  • See all documentation

okay that's the whole page bestie, you're officially educated πŸ’œ go forth and encode 🫢

$DATE Β· $VERSION Β· GOLF(2gg) β€” that's the source, version and date sign-off, slay 🌟
πŸ“¦ where this page comes from