GOLF(2gg)
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-base64encode-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
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms