Base64 encode data: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 5: Line 5:


=={{header|ABAP}}==
=={{header|ABAP}}==
<lang ABAP>DATA: li_client TYPE REF TO if_http_client,
<syntaxhighlight lang=ABAP>DATA: li_client TYPE REF TO if_http_client,
lv_encoded TYPE string,
lv_encoded TYPE string,
lv_data TYPE xstring.
lv_data TYPE xstring.
Line 32: Line 32:
ENDWHILE.
ENDWHILE.
WRITE: / lv_encoded.
WRITE: / lv_encoded.
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 43: Line 43:
=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit
<syntaxhighlight lang=Action!>INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit


PROC Encode(BYTE ARRAY buf BYTE len CHAR ARRAY res)
PROC Encode(BYTE ARRAY buf BYTE len CHAR ARRAY res)
Line 95: Line 95:
PROC Main()
PROC Main()
EncodeFile("H1:FAVICON.ICO")
EncodeFile("H1:FAVICON.ICO")
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Base64_encode_data.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Base64_encode_data.png Screenshot from Atari 8-bit computer]
Line 106: Line 106:
=={{header|Ada}}==
=={{header|Ada}}==
{{libheader|AWS}}
{{libheader|AWS}}
<lang Ada>with Ada.Text_IO;
<syntaxhighlight lang=Ada>with Ada.Text_IO;


with AWS.Response;
with AWS.Response;
Line 119: Line 119:
begin
begin
Ada.Text_IO.Put_Line (Icon_64);
Ada.Text_IO.Put_Line (Icon_64);
end Encode_AWS;</lang>
end Encode_AWS;</syntaxhighlight>


{{out}}
{{out}}
Line 130: Line 130:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
This program is run on a modified Algol 68 Genie 2.8. That interpreter has some bugs, so it does not do binary tcp/ip requests, and I made patches/bugfixes to it in order to run this task.
This program is run on a modified Algol 68 Genie 2.8. That interpreter has some bugs, so it does not do binary tcp/ip requests, and I made patches/bugfixes to it in order to run this task.
<lang algol68>
<syntaxhighlight lang=algol68>
STRING codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[@0];
STRING codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[@0];


Line 194: Line 194:
STRING encoded icon = base64_encode (rosettacode icon);
STRING encoded icon = base64_encode (rosettacode icon);
print ((encoded icon, new line))
print ((encoded icon, new line))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 204: Line 204:


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
<lang ARM Assembly>
<syntaxhighlight lang=ARM Assembly>
.section .rodata
.section .rodata
ch64: .ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
ch64: .ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Line 371: Line 371:
mov r0, #0
mov r0, #0
swi #0
swi #0
</syntaxhighlight>
</lang>


=={{header|BaCon}}==
=={{header|BaCon}}==
<lang bacon>CONST file$ = "favicon.ico"
<syntaxhighlight lang=bacon>CONST file$ = "favicon.ico"
binary = BLOAD(file$)
binary = BLOAD(file$)
PRINT B64ENC$(binary, FILELEN(file$))
PRINT B64ENC$(binary, FILELEN(file$))
FREE binary</lang>
FREE binary</syntaxhighlight>
{{out}}
{{out}}
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAE.......QAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAE=</pre>
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAE.......QAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAE=</pre>
Line 384: Line 384:
===libresolv===
===libresolv===
{{libheader|libresolv}} (libresolv is included on most Unix-like systems)
{{libheader|libresolv}} (libresolv is included on most Unix-like systems)
<lang c>#include <stdio.h>
<syntaxhighlight lang=c>#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <resolv.h>
#include <resolv.h>
Line 422: Line 422:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
Compile with
Compile with
<pre>gcc -lresolv -o base64encode base64encode.c</pre>
<pre>gcc -lresolv -o base64encode base64encode.c</pre>
Line 428: Line 428:
===Manual implementation===
===Manual implementation===
The following reads standard input and writes base64-encoded stream to standard output, e.g. <tt>./a.out <some_random_file >/dev/null</tt> if you don't want to see the output. It gives identical output as the common <tt>base64</tt> utility program, though much less efficiently.
The following reads standard input and writes base64-encoded stream to standard output, e.g. <tt>./a.out <some_random_file >/dev/null</tt> if you don't want to see the output. It gives identical output as the common <tt>base64</tt> utility program, though much less efficiently.
<lang c>#include <stdio.h>
<syntaxhighlight lang=c>#include <stdio.h>
#include <unistd.h>
#include <unistd.h>


Line 458: Line 458:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>namespace RosettaCode.Base64EncodeData
<syntaxhighlight lang=csharp>namespace RosettaCode.Base64EncodeData
{
{
using System;
using System;
Line 482: Line 482:
}
}
}
}
}</lang>
}</syntaxhighlight>
Output:
Output:
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAg...AAABAAAAAQAAAAEAAAABAAAAAQAAAAE=</pre>
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAg...AAABAAAAAQAAAAEAAAABAAAAAQAAAAE=</pre>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>
<syntaxhighlight lang=cpp>
#include <iostream>
#include <iostream>
#include <fstream>
#include <fstream>
Line 544: Line 544:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 557: Line 557:
Assumes the source file is a PRG on disk drive device 8, writes encoded file both to a SEQ file on the same disk and to the screen (where it looks good in 80-column mode on a PET or C128, a little less so on a C64 or VIC). This is all done in PETSCII; transfer out of Commodore-land will require translation of the Base64-encoded file into ASCII.
Assumes the source file is a PRG on disk drive device 8, writes encoded file both to a SEQ file on the same disk and to the screen (where it looks good in 80-column mode on a PET or C128, a little less so on a C64 or VIC). This is all done in PETSCII; transfer out of Commodore-land will require translation of the Base64-encoded file into ASCII.


<lang basic>
<syntaxhighlight lang=basic>
100 print chr$(247);chr$(14);
100 print chr$(247);chr$(14);
110 dim a$(63): rem alphabet
110 dim a$(63): rem alphabet
Line 595: Line 595:
450 print "error:"st
450 print "error:"st
460 open 15,8,15:input#15,ds,ds$,a,b:close15
460 open 15,8,15:input#15,ds,ds$,a,b:close15
470 print ds,ds$,a,b</lang>
470 print ds,ds$,a,b</syntaxhighlight>


{{Out}}
{{Out}}
Line 609: Line 609:
A nice example for the CL eco system using [http://quickdocs.org/cl-base64/ cl-base64] and [https://www.cliki.net/Drakma drakma].
A nice example for the CL eco system using [http://quickdocs.org/cl-base64/ cl-base64] and [https://www.cliki.net/Drakma drakma].
<lang lisp>(eval-when (:load-toplevel :compile-toplevel :execute)
<syntaxhighlight lang=lisp>(eval-when (:load-toplevel :compile-toplevel :execute)
(ql:quickload "drakma")
(ql:quickload "drakma")
(ql:quickload "cl-base64"))
(ql:quickload "cl-base64"))
Line 630: Line 630:
finally (return (usb8-array-to-base64-string array)))))
finally (return (usb8-array-to-base64-string array)))))
(close input)
(close input)
output))</lang>
output))</syntaxhighlight>
{{out}}
{{out}}
<pre>"AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///...</pre>
<pre>"AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///...</pre>


=={{header|Crystal}}==
=={{header|Crystal}}==
<lang ruby>
<syntaxhighlight lang=ruby>
require "http/client"
require "http/client"
require "base64"
require "base64"
Line 643: Line 643:
Base64.encode(response.body, STDOUT)
Base64.encode(response.body, STDOUT)
end
end
</syntaxhighlight>
</lang>




=={{header|D}}==
=={{header|D}}==
<lang d>void main() {
<syntaxhighlight lang=d>void main() {
import std.stdio, std.base64, std.net.curl, std.string;
import std.stdio, std.base64, std.net.curl, std.string;


const f = "http://rosettacode.org/favicon.ico".get.representation;
const f = "http://rosettacode.org/favicon.ico".get.representation;
Base64.encode(f).writeln;
Base64.encode(f).writeln;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAwqgIAADCjgUAACgAAAAQAAAAIAA...
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAwqgIAADCjgUAACgAAAAQAAAAIAA...
Line 658: Line 658:


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang delphi>program Base64EncodeData;
<syntaxhighlight lang=delphi>program Base64EncodeData;
{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
uses IdHTTP, IdCoderMIME;
uses IdHTTP, IdCoderMIME;
Line 673: Line 673:
lHTTP.Free;
lHTTP.Free;
end;
end;
end.</lang>
end.</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>data = File.read!("favicon.ico")
<syntaxhighlight lang=elixir>data = File.read!("favicon.ico")
encoded = :base64.encode(data)
encoded = :base64.encode(data)
IO.puts encoded</lang>
IO.puts encoded</syntaxhighlight>


{{out}}
{{out}}
Line 688: Line 688:


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>-module(base64demo).
<syntaxhighlight lang=erlang>-module(base64demo).
-export([main/0]).
-export([main/0]).


Line 698: Line 698:
%% Demonstrating with the library function.
%% Demonstrating with the library function.
encode_library(Data) ->
encode_library(Data) ->
base64:encode(Data).</lang>
base64:encode(Data).</syntaxhighlight>


{{out}}
{{out}}
Line 706: Line 706:
===Standard Library===
===Standard Library===
{{works with|fsharp|4.5}}
{{works with|fsharp|4.5}}
<lang fsharp>open System
<syntaxhighlight lang=fsharp>open System
open System.Net
open System.Net


Line 718: Line 718:
let encoded = Convert.ToBase64String raw
let encoded = Convert.ToBase64String raw


printfn "%s" encoded</lang>
printfn "%s" encoded</syntaxhighlight>


{{out}}
{{out}}
Line 725: Line 725:
===Manual Implementation===
===Manual Implementation===
{{works with|fsharp|4.5}}
{{works with|fsharp|4.5}}
<lang fsharp>open System.Net
<syntaxhighlight lang=fsharp>open System.Net


let encode s =
let encode s =
Line 755: Line 755:


printfn "%s" encoded
printfn "%s" encoded
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 761: Line 761:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: base64 http.client io kernel strings ;
<syntaxhighlight lang=factor>USING: base64 http.client io kernel strings ;


"http://rosettacode.org/favicon.ico" http-get nip
"http://rosettacode.org/favicon.ico" http-get nip
>base64-lines >string print</lang>
>base64-lines >string print</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 776: Line 776:
Inspired from Wikipedia. Use of a buffer.
Inspired from Wikipedia. Use of a buffer.
May be also of interest : github.com/lietho/base64-forth
May be also of interest : github.com/lietho/base64-forth
<lang forth>variable bitsbuff
<syntaxhighlight lang=forth>variable bitsbuff


: alphabase ( u -- c ) $3F and C" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 1+ + c@ ;
: alphabase ( u -- c ) $3F and C" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 1+ + c@ ;
Line 805: Line 805:
dup here swap - ( addr2 n2 )
dup here swap - ( addr2 n2 )
;
;
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 820: Line 820:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Dim Shared As String B64
<syntaxhighlight lang=freebasic>Dim Shared As String B64
B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"abcdefghijklmnopqrstuvwxyz" & _
"abcdefghijklmnopqrstuvwxyz" & _
Line 860: Line 860:
Print msg64
Print msg64
Print: Print(Encode64(msg64))
Print: Print(Encode64(msg64))
Sleep</lang>
Sleep</syntaxhighlight>
{{out}}
{{out}}
<pre>To err is human, but to really foul things up you need a computer.
<pre>To err is human, but to really foul things up you need a computer.
Line 870: Line 870:
=={{header|Go}}==
=={{header|Go}}==
===Standard Library===
===Standard Library===
<lang Go>package main
<syntaxhighlight lang=Go>package main


import (
import (
Line 892: Line 892:
}
}
fmt.Println(base64.StdEncoding.EncodeToString(d))
fmt.Println(base64.StdEncoding.EncodeToString(d))
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 898: Line 898:
</pre>
</pre>
===Manual implementation===
===Manual implementation===
<lang go>// base64 encoding
<syntaxhighlight lang=go>// base64 encoding
// A port, with slight variations, of the C version found here:
// A port, with slight variations, of the C version found here:
// http://rosettacode.org/wiki/Base64#C (manual implementation)
// http://rosettacode.org/wiki/Base64#C (manual implementation)
Line 998: Line 998:
}
}
fmt.Printf("%s", encoded)
fmt.Printf("%s", encoded)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,012: Line 1,012:
{{Trans|C}}
{{Trans|C}}
This Haskell code is ported from the C solution (manual implementation) with slight variations.
This Haskell code is ported from the C solution (manual implementation) with slight variations.
<lang Haskell>-- | Base 64 Encoding.
<syntaxhighlight lang=Haskell>-- | Base 64 Encoding.
-- A port, with slight variations, of the C version found here:
-- A port, with slight variations, of the C version found here:
-- http://rosettacode.org/wiki/Base64#C (manual implementation)
-- http://rosettacode.org/wiki/Base64#C (manual implementation)
Line 1,077: Line 1,077:


main :: IO ()
main :: IO ()
main = C.getContents >>= C.putStr . b64EncodePretty</lang>
main = C.getContents >>= C.putStr . b64EncodePretty</syntaxhighlight>


===Using Data.ByteString.Base64===
===Using Data.ByteString.Base64===
<lang haskell>import qualified Data.ByteString.Base64 as Base64 (decode, encode)
<syntaxhighlight lang=haskell>import qualified Data.ByteString.Base64 as Base64 (decode, encode)
import qualified Data.ByteString.Char8 as B (putStrLn, readFile)
import qualified Data.ByteString.Char8 as B (putStrLn, readFile)


main :: IO ()
main :: IO ()
main = B.readFile "favicon.ico" >>= (B.putStrLn . Base64.encode)</lang>
main = B.readFile "favicon.ico" >>= (B.putStrLn . Base64.encode)</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
'''Solution''' (''[http://www.jsoftware.com/wsvn/addons/trunk/convert/misc/base64.ijs standard library]''):<lang j> load'convert/misc/base64' NB. use 'tobase64'</lang>
'''Solution''' (''[http://www.jsoftware.com/wsvn/addons/trunk/convert/misc/base64.ijs standard library]''):<syntaxhighlight lang=j> load'convert/misc/base64' NB. use 'tobase64'</syntaxhighlight>
'''Solution''' (''handrolled''):<lang j> tobase64 =: padB64~ b2B64
'''Solution''' (''handrolled''):<syntaxhighlight lang=j> tobase64 =: padB64~ b2B64
padB64 =: , '=' #~ 0 2 1 i. 3 | #
padB64 =: , '=' #~ 0 2 1 i. 3 | #
b2B64 =: BASE64 {~ _6 #.\ (8#2) ,@:#: a.&i.</lang>
b2B64 =: BASE64 {~ _6 #.\ (8#2) ,@:#: a.&i.</syntaxhighlight>
'''Example''':<lang j> load'web/gethttp'
'''Example''':<syntaxhighlight lang=j> load'web/gethttp'
76 {. tobase64 gethttp 'http://rosettacode.org/favicon.ico'
76 {. tobase64 gethttp 'http://rosettacode.org/favicon.ico'
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAA</lang>
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAA</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
Line 1,099: Line 1,099:
Can also use org.apache.commons.codec.binary.Base64 from Apache Commons Codec
Can also use org.apache.commons.codec.binary.Base64 from Apache Commons Codec


<lang Java>import java.io.ByteArrayInputStream;
<syntaxhighlight lang=Java>import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStream;
Line 1,169: Line 1,169:
}
}
}
}
}</lang>
}</syntaxhighlight>
<pre>AAABAAIAEBAAAAAAAABoBQ...QAAAAEAAAABAAAAAQAAAAE=</pre>
<pre>AAABAAIAEBAAAAAAAABoBQ...QAAAAEAAAABAAAAAQAAAAE=</pre>


=== Java 8 version ===
=== Java 8 version ===
<lang java>import java.nio.file.*;
<syntaxhighlight lang=java>import java.nio.file.*;
import java.util.Base64;
import java.util.Base64;


Line 1,183: Line 1,183:
System.out.println(result);
System.out.println(result);
}
}
}</lang>
}</syntaxhighlight>


<pre>AAABAAIAEBAAAAAAAABoBQ...QAAAAEAAAABAAAAAQAAAAE=</pre>
<pre>AAABAAIAEBAAAAAAAABoBQ...QAAAAEAAAABAAAAAQAAAAE=</pre>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang JavaScript>(function(){//ECMAScript doesn't have an internal base64 function or method, so we have to do it ourselves, isn't that exciting?
<syntaxhighlight lang=JavaScript>(function(){//ECMAScript doesn't have an internal base64 function or method, so we have to do it ourselves, isn't that exciting?
function stringToArrayUnicode(str){for(var i=0,l=str.length,n=[];i<l;i++)n.push(str.charCodeAt(i));return n;}
function stringToArrayUnicode(str){for(var i=0,l=str.length,n=[];i<l;i++)n.push(str.charCodeAt(i));return n;}
function generateOnesByLength(n){//Attempts to generate a binary number full of ones given a length.. they don't redefine each other that much.
function generateOnesByLength(n){//Attempts to generate a binary number full of ones given a length.. they don't redefine each other that much.
Line 1,252: Line 1,252:


return toBase64(stringToArrayUnicode("Nothing seems hard to the people who don't know what they're talking about."))
return toBase64(stringToArrayUnicode("Nothing seems hard to the people who don't know what they're talking about."))
}())</lang>
}())</syntaxhighlight>


===Using btoa (HTML5)===
===Using btoa (HTML5)===
Line 1,260: Line 1,260:
HTML5 saves the day! introducing two methods to the DOM!
HTML5 saves the day! introducing two methods to the DOM!
These are btoa and atob, see [http://dev.w3.org/html5/spec-LC/webappapis.html#atob spec]
These are btoa and atob, see [http://dev.w3.org/html5/spec-LC/webappapis.html#atob spec]
<lang JavaScript>window.btoa("String to encode, etc..");//Will throw error if any unicode character is larger than 255 it's counterpart it's the window.atob</lang>To make it.. just work, you could convert it to UTF-8 Manually or..
<syntaxhighlight lang=JavaScript>window.btoa("String to encode, etc..");//Will throw error if any unicode character is larger than 255 it's counterpart it's the window.atob</syntaxhighlight>To make it.. just work, you could convert it to UTF-8 Manually or..
JSON.stringify it or..
JSON.stringify it or..
encodeURIComponent it.
encodeURIComponent it.
Line 1,266: Line 1,266:
===Using Node.js===
===Using Node.js===
{{works with|Node.js}}
{{works with|Node.js}}
<lang JavaScript>var http = require('http');
<syntaxhighlight lang=JavaScript>var http = require('http');
var options = {
var options = {
host: 'rosettacode.org',
host: 'rosettacode.org',
Line 1,280: Line 1,280:
});
});
}
}
</syntaxhighlight>
</lang>


=={{header|Jsish}}==
=={{header|Jsish}}==
Line 1,286: Line 1,286:
<nowiki>https://jsish.org/fossil/jsi/wiki/Wget</nowiki> and also listed at [[HTTP#Jsish]].
<nowiki>https://jsish.org/fossil/jsi/wiki/Wget</nowiki> and also listed at [[HTTP#Jsish]].


<lang javascript>/* Base64, in Jsish */
<syntaxhighlight lang=javascript>/* Base64, in Jsish */
require('httpGet');
require('httpGet');
var icon = httpGet('http://rosettacode.org/favicon.ico');
var icon = httpGet('http://rosettacode.org/favicon.ico');
printf("%s", Util.base64(icon, false))</lang>
printf("%s", Util.base64(icon, false))</syntaxhighlight>


{{out}}
{{out}}
Line 1,311: Line 1,311:
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>using Requests
<syntaxhighlight lang=julia>using Requests


file = read(get("https://rosettacode.org/favicon.ico"))
file = read(get("https://rosettacode.org/favicon.ico"))
encoded = base64encode(file)
encoded = base64encode(file)


print(encoded)</lang>
print(encoded)</syntaxhighlight>


{{out}}
{{out}}
Line 1,322: Line 1,322:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.1.2
<syntaxhighlight lang=scala>// version 1.1.2


import java.io.File
import java.io.File
Line 1,332: Line 1,332:
val base64 = Base64.getEncoder().encodeToString(bytes)
val base64 = Base64.getEncoder().encodeToString(bytes)
println(base64)
println(base64)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,340: Line 1,340:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso >local(
<syntaxhighlight lang=Lasso >local(
src = curl('http://rosettacode.org/favicon.ico'),
src = curl('http://rosettacode.org/favicon.ico'),
srcdata = #src->result
srcdata = #src->result
Line 1,347: Line 1,347:


// or, in one movement:
// or, in one movement:
curl('http://rosettacode.org/favicon.ico')->result->encodebase64</lang>
curl('http://rosettacode.org/favicon.ico')->result->encodebase64</syntaxhighlight>


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>put URL "http://rosettacode.org/favicon.ico" into rosettaico
<syntaxhighlight lang=LiveCode>put URL "http://rosettacode.org/favicon.ico" into rosettaico
put base64encode(rosettaico)
put base64encode(rosettaico)


Ouput
Ouput
AAABAA...S0tLS0tLS0t...QAAAAE=</lang>
AAABAA...S0tLS0tLS0t...QAAAAE=</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>
<syntaxhighlight lang=lua>
local dic = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
local dic = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
function encode( t, f )
function encode( t, f )
Line 1,389: Line 1,389:
end
end
print()
print()
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,400: Line 1,400:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>ExportString[Import["http://rosettacode.org/favicon.ico", "Text"], "Base64"]</lang>
<syntaxhighlight lang=Mathematica>ExportString[Import["http://rosettacode.org/favicon.ico", "Text"], "Base64"]</syntaxhighlight>
Very interesting results.
Very interesting results.
{{out}}
{{out}}
Line 1,412: Line 1,412:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import base64
<syntaxhighlight lang=Nim>import base64
import httpclient
import httpclient


Line 1,422: Line 1,422:
echo encoded
echo encoded
else:
else:
echo encoded[0..31] & "..." & encoded[^32..^1]</lang>
echo encoded[0..31] & "..." & encoded[^32..^1]</syntaxhighlight>


{{out}}
{{out}}
Line 1,430: Line 1,430:
{{works with|Mac OS X|10.6+}}
{{works with|Mac OS X|10.6+}}
{{works with|iOS|4.0+}}
{{works with|iOS|4.0+}}
<lang objc>#import <Foundation/Foundation.h>
<syntaxhighlight lang=objc>#import <Foundation/Foundation.h>


int main(int argc, const char *argv[]) {
int main(int argc, const char *argv[]) {
Line 1,438: Line 1,438:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 1,469: Line 1,469:


=={{header|Ol}}==
=={{header|Ol}}==
<lang scheme>
<syntaxhighlight lang=scheme>
(define base64-codes "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
(define base64-codes "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
(define kernel (alist->ff (map cons (iota (string-length base64-codes)) (string->bytes base64-codes))))
(define kernel (alist->ff (map cons (iota (string-length base64-codes)) (string->bytes base64-codes))))
Line 1,518: Line 1,518:


(encode "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 in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.")
(encode "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 in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.")
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,527: Line 1,527:


The rosettacode icon:
The rosettacode icon:
<lang scheme>
<syntaxhighlight lang=scheme>
(define icon (runes->string (bytevector->list (file->bytevector "favicon.ico"))))
(define icon (runes->string (bytevector->list (file->bytevector "favicon.ico"))))
(encode icon)
(encode icon)
</syntaxhighlight>
</lang>
<pre>
<pre>
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wCG
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wCG
Line 1,538: Line 1,538:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>#!perl
<syntaxhighlight lang=perl>#!perl
use strict;
use strict;
use warnings;
use warnings;
Line 1,545: Line 1,545:
local $/;
local $/;
print encode_base64(<$fh>);
print encode_base64(<$fh>);
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,554: Line 1,554:
=={{header|Phix}}==
=={{header|Phix}}==
For simplicity, the example from wp:
For simplicity, the example from wp:
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">base64</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">base64</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,565: Line 1,565:
<span style="color: #0000FF;">?</span><span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">decode_base64</span><span style="color: #0000FF;">(</span><span style="color: #000000;">e</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">decode_base64</span><span style="color: #0000FF;">(</span><span style="color: #000000;">e</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,576: Line 1,576:
This downloads, encodes, decodes, and verifies the icon:
This downloads, encodes, decodes, and verifies the icon:
{{libheader|Phix/libcurl}}
{{libheader|Phix/libcurl}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"https://rosettacode.org/favicon.ico"</span><span style="color: #0000FF;">,</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"https://rosettacode.org/favicon.ico"</span><span style="color: #0000FF;">,</span>
Line 1,596: Line 1,596:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"base 64: %s, same: %t\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b64</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"chars"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">chk</span><span style="color: #0000FF;">==</span><span style="color: #000000;">raw</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"base 64: %s, same: %t\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b64</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"chars"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">chk</span><span style="color: #0000FF;">==</span><span style="color: #000000;">raw</span><span style="color: #0000FF;">})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,606: Line 1,606:


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php echo base64_encode(file_get_contents("http://rosettacode.org/favicon.ico"));/*1 liner*/ ?></lang>
<syntaxhighlight lang=php><?php echo base64_encode(file_get_contents("http://rosettacode.org/favicon.ico"));/*1 liner*/ ?></syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>`(== 64 64)
<syntaxhighlight lang=PicoLisp>`(== 64 64)
(setq *Char64
(setq *Char64
`'(chop
`'(chop
Line 1,653: Line 1,653:
(test
(test
"c3VyZS4="
"c3VyZS4="
(base64 "sure.") )</lang>
(base64 "sure.") )</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang Pike>
<syntaxhighlight lang=Pike>
string icon = Protocols.HTTP.get_url_data("http://rosettacode.org/favicon.ico");
string icon = Protocols.HTTP.get_url_data("http://rosettacode.org/favicon.ico");
// The default base64 encodeing linefeeds every 76 chars
// The default base64 encodeing linefeeds every 76 chars
Line 1,662: Line 1,662:
// For brivety, just print the first and last line
// For brivety, just print the first and last line
write("%s\n...\n%s\n", encoded_lines[0], encoded_lines[-1]);
write("%s\n...\n%s\n", encoded_lines[0], encoded_lines[-1]);
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,671: Line 1,671:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang PowerShell>$webClient = [Net.WebClient]::new()
<syntaxhighlight lang=PowerShell>$webClient = [Net.WebClient]::new()
$bytes = $webClient.DownloadData('http://rosettacode.org/favicon.ico')
$bytes = $webClient.DownloadData('http://rosettacode.org/favicon.ico')
$output = [Convert]::ToBase64String($bytes)
$output = [Convert]::ToBase64String($bytes)
$output</lang>
$output</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,683: Line 1,683:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang purebasic>InitNetwork()
<syntaxhighlight lang=purebasic>InitNetwork()
*BufferRaw = ReceiveHTTPMemory("http://rosettacode.org/favicon.ico")
*BufferRaw = ReceiveHTTPMemory("http://rosettacode.org/favicon.ico")
Line 1,690: Line 1,690:
Else
Else
Debug "Download failed"
Debug "Download failed"
EndIf</lang>
EndIf</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>import urllib
<syntaxhighlight lang=python>import urllib
import base64
import base64


data = urllib.urlopen('http://rosettacode.org/favicon.ico').read()
data = urllib.urlopen('http://rosettacode.org/favicon.ico').read()
print base64.b64encode(data)</lang>
print base64.b64encode(data)</syntaxhighlight>
(For me this gets the wrong data; the data is actually an error message. But still, it base-64 encodes it.)
(For me this gets the wrong data; the data is actually an error message. But still, it base-64 encodes it.)


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>
<syntaxhighlight lang=racket>
#lang racket
#lang racket
(require net/url net/base64)
(require net/url net/base64)
(base64-encode (call/input-url (string->url "http://rosettacode.org/favicon.ico")
(base64-encode (call/input-url (string->url "http://rosettacode.org/favicon.ico")
get-pure-port port->bytes))
get-pure-port port->bytes))
</syntaxhighlight>
</lang>
Output:
Output:
<lang racket>
<syntaxhighlight lang=racket>
#"AAABAAIAEBAAAAAAAABoBQAA...AQAAAAE=\r\n"
#"AAABAAIAEBAAAAAAAABoBQAA...AQAAAAE=\r\n"
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>sub MAIN {
<syntaxhighlight lang=raku line>sub MAIN {
my $buf = slurp("./favicon.ico", :bin);
my $buf = slurp("./favicon.ico", :bin);
say buf-to-Base64($buf);
say buf-to-Base64($buf);
Line 1,736: Line 1,736:
else { take '==' }
else { take '==' }
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAA...QAAAAEAAAABAAAAAQAAAAE=</pre>
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAA...QAAAAEAAAABAAAAAQAAAAE=</pre>


=={{header|Red}}==
=={{header|Red}}==
<lang red>Red [Source: https://github.com/vazub/rosetta-red]
<syntaxhighlight lang=red>Red [Source: https://github.com/vazub/rosetta-red]


print enbase read/binary https://rosettacode.org/favicon.ico
print enbase read/binary https://rosettacode.org/favicon.ico
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,755: Line 1,755:


A much higher value for &nbsp; '''chunk''' &nbsp; could be used for modern systems or implementations.
A much higher value for &nbsp; '''chunk''' &nbsp; could be used for modern systems or implementations.
<lang rexx>/*REXX program converts text (from a file or the C.L.) to a base64 text string. */
<syntaxhighlight lang=rexx>/*REXX program converts text (from a file or the C.L.) to a base64 text string. */
parse arg iFID @ /*obtain optional arguments from the CL*/
parse arg iFID @ /*obtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID='favicon.ico' /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='favicon.ico' /*Not specified? Then use the default.*/
Line 1,784: Line 1,784:
end /*j*/
end /*j*/
/* [↓] maybe append equal signs to $. */
/* [↓] maybe append equal signs to $. */
return $ || copies('=', 2 * (L//6==2) + (L//6==4) )</lang>
return $ || copies('=', 2 * (L//6==2) + (L//6==4) )</syntaxhighlight>
For the various outputs, several input texts from the Wikipedia article on &nbsp; ''Base64'' &nbsp; [http://en.wikipedia.org/wiki/Base64] &nbsp; were used to demonstrate how padding works.
For the various outputs, several input texts from the Wikipedia article on &nbsp; ''Base64'' &nbsp; [http://en.wikipedia.org/wiki/Base64] &nbsp; were used to demonstrate how padding works.
<br><br>
<br><br>
Line 1,824: Line 1,824:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang=ring>
#=======================================#
#=======================================#
# Description : Base64 Sample
# Description : Base64 Sample
Line 1,851: Line 1,851:
oQByteArray.append("bXkgc3RyaW5n")
oQByteArray.append("bXkgc3RyaW5n")
? oQByteArray.fromBase64(oQByteArray).data()
? oQByteArray.fromBase64(oQByteArray).data()
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,859: Line 1,859:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>require 'open-uri'
<syntaxhighlight lang=ruby>require 'open-uri'
require 'base64'
require 'base64'


puts Base64.encode64 open('http://rosettacode.org/favicon.ico') {|f| f.read}</lang>
puts Base64.encode64 open('http://rosettacode.org/favicon.ico') {|f| f.read}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang Scala>import java.net.URL
<syntaxhighlight lang=Scala>import java.net.URL
import java.util.Base64
import java.util.Base64


Line 1,878: Line 1,878:


println(s"Successfully completed without errors. [total ${compat.Platform.currentTime - executionStart} ms]")
println(s"Successfully completed without errors. [total ${compat.Platform.currentTime - executionStart} ms]")
}</lang>
}</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==
Line 1,885: Line 1,885:
which encodes a string with the Base64 encoding.
which encodes a string with the Base64 encoding.


<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang=seed7>$ include "seed7_05.s7i";
include "gethttp.s7i";
include "gethttp.s7i";
include "encoding.s7i";
include "encoding.s7i";
Line 1,892: Line 1,892:
begin
begin
writeln(toBase64(getHttp("rosettacode.org/favicon.ico")));
writeln(toBase64(getHttp("rosettacode.org/favicon.ico")));
end func;</lang>
end func;</syntaxhighlight>


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<lang sensetalk>
<syntaxhighlight lang=sensetalk>
put "To err is human, but to really foul things up you need a computer. --Paul R.Ehrlich" as base64
put "To err is human, but to really foul things up you need a computer. --Paul R.Ehrlich" as base64
put base64Encode ("To err is human, but to really foul things up you need a computer. --Paul R.Ehrlich")
put base64Encode ("To err is human, but to really foul things up you need a computer. --Paul R.Ehrlich")
</syntaxhighlight>
</lang>
Output:
Output:
<lang sensetalk>
<syntaxhighlight lang=sensetalk>
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVk
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVk
IGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=
IGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=
Line 1,906: Line 1,906:
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVk
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVk
IGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=
IGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=
</syntaxhighlight>
</lang>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var data = %f'favicon.ico'.read(:raw) # binary string
<syntaxhighlight lang=ruby>var data = %f'favicon.ico'.read(:raw) # binary string
print data.encode_base64 # print to STDOUT</lang>
print data.encode_base64 # print to STDOUT</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
{{works with|Tcl|8.6}}
<lang tcl>package require Tcl 8.6
<syntaxhighlight lang=tcl>package require Tcl 8.6
package require http
package require http


Line 1,921: Line 1,921:
http::cleanup $tok
http::cleanup $tok


puts [binary encode base64 -maxlen 64 $icondata]</lang>
puts [binary encode base64 -maxlen 64 $icondata]</syntaxhighlight>
With older versions of Tcl, the base64 encoding is best supported via an external package:
With older versions of Tcl, the base64 encoding is best supported via an external package:
{{tcllib|base64}}
{{tcllib|base64}}
<lang tcl>package require base64
<syntaxhighlight lang=tcl>package require base64
package require http
package require http


Line 1,931: Line 1,931:
http::cleanup $tok
http::cleanup $tok


puts [base64::encode -maxlen 64 $icondata]</lang>
puts [base64::encode -maxlen 64 $icondata]</syntaxhighlight>


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Option Explicit
<syntaxhighlight lang=vb>Option Explicit
Public Function Decode(s As String) As String
Public Function Decode(s As String) As String
Dim i As Integer, j As Integer, r As Byte
Dim i As Integer, j As Integer, r As Byte
Line 2,042: Line 2,042:
Debug.Print "Result of string comparison of input and decoded output: " & StrComp(In_, bIn, vbBinaryCompare)
Debug.Print "Result of string comparison of input and decoded output: " & StrComp(In_, bIn, vbBinaryCompare)
Debug.Print "A zero indicates both strings are equal."
Debug.Print "A zero indicates both strings are equal."
End Sub</lang>
End Sub</syntaxhighlight>
{{out}}<pre>The first eighty and last eighty characters after encoding:
{{out}}<pre>The first eighty and last eighty characters after encoding:
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEAB
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEAB
Line 2,054: Line 2,054:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
From first principles using string manipulation. Quick enough here.
From first principles using string manipulation. Quick enough here.
<lang ecmascript>import "io" for File, Stdout
<syntaxhighlight lang=ecmascript>import "io" for File, Stdout
import "/fmt" for Conv, Fmt
import "/fmt" for Conv, Fmt
import "/seq" for Lst
import "/seq" for Lst
Line 2,086: Line 2,086:
var s = File.read("favicon.ico").bytes.toList
var s = File.read("favicon.ico").bytes.toList
for (chunk in Lst.chunks(s, 3)) encode.call(chunk)
for (chunk in Lst.chunks(s, 3)) encode.call(chunk)
System.print()</lang>
System.print()</syntaxhighlight>


{{out}}
{{out}}
Line 2,097: Line 2,097:
=={{header|zkl}}==
=={{header|zkl}}==
Using shared libraries for cURL and message hashing:
Using shared libraries for cURL and message hashing:
<lang zkl>var [const] MsgHash=Import("zklMsgHash"), Curl=Import("zklCurl");
<syntaxhighlight lang=zkl>var [const] MsgHash=Import("zklMsgHash"), Curl=Import("zklCurl");
icon:=Curl().get("http://rosettacode.org/favicon.ico"); //-->(Data(4,331),693,0)
icon:=Curl().get("http://rosettacode.org/favicon.ico"); //-->(Data(4,331),693,0)
Line 2,105: Line 2,105:
icon==MsgHash.base64decode(b64));
icon==MsgHash.base64decode(b64));
b64.println();
b64.println();
b64.text.println();</lang>
b64.text.println();</syntaxhighlight>
{{out}}
{{out}}
Encoded to 72 characters per line
Encoded to 72 characters per line