Base64 encode data: Difference between revisions

m
→‎{{header|Phix}}: added icon downloading version
m (→‎{{header|Phix}}: added icon downloading version)
Line 1,398:
"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight i
n the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."
</pre>
This downloads, encodes, decodes, and verifies the icon:
<lang Phix>constant url = "https://rosettacode.org/favicon.ico",
out = get_file_name(url)
printf(1, "\nattempting to download remote file %s to local file %s\n\n", {url,out})
 
include libcurl.e
 
CURLcode res = curl_easy_get_file(url,"",out) -- (no proxy)
if res!=CURLE_OK then
printf(1, "Error %d downloading file\n", res)
else
printf(1, "file %s saved\n", {out})
end if
string raw = get_text(out,GT_WHOLE_FILE+GT_BINARY),
b64 = encode_base64(raw),
chk = decode_base64(b64)
 
printf(1,"base 64: %s, same: %t\n",{shorten(b64,"chars"),chk==raw})</lang>
{{out}}
<pre>
attempting to download remote file https://rosettacode.org/favicon.ico to local file favicon.ico
 
file favicon.ico saved
base 64: AAABAAIAEBAAAAAAAABo...AAEAAAABAAAAAQAAAAE= (4,852 chars), same: true
</pre>
 
7,794

edits