1
2[//000000001]: # (base64 \- Text encoding & decoding binary data)
3[//000000002]: # (Generated from file 'base64\.man' by tcllib/doctools with format 'markdown')
4[//000000003]: # (Copyright © 2000, Eric Melski)
5[//000000004]: # (Copyright © 2001, Miguel Sofer)
6[//000000005]: # (base64\(n\) 2\.4\.2 tcllib "Text encoding & decoding binary data")
7
8<hr> [ <a href="../../../../toc.md">Main Table Of Contents</a> &#124; <a
9href="../../../toc.md">Table Of Contents</a> &#124; <a
10href="../../../../index.md">Keyword Index</a> &#124; <a
11href="../../../../toc0.md">Categories</a> &#124; <a
12href="../../../../toc1.md">Modules</a> &#124; <a
13href="../../../../toc2.md">Applications</a> ] <hr>
14
15# NAME
16
17base64 \- base64\-encode/decode binary data
18
19# <a name='toc'></a>Table Of Contents
20
21  - [Table Of Contents](#toc)
22
23  - [Synopsis](#synopsis)
24
25  - [Description](#section1)
26
27  - [EXAMPLES](#section2)
28
29  - [Bugs, Ideas, Feedback](#section3)
30
31  - [Keywords](#keywords)
32
33  - [Category](#category)
34
35  - [Copyright](#copyright)
36
37# <a name='synopsis'></a>SYNOPSIS
38
39package require Tcl 8
40package require base64 ?2\.4\.2?
41
42[__::base64::encode__ ?__\-maxlen__ *maxlen*? ?__\-wrapchar__ *wrapchar*? *string*](#1)
43[__::base64::decode__ *string*](#2)
44
45# <a name='description'></a>DESCRIPTION
46
47This package provides procedures to encode binary data into base64 and back\.
48
49  - <a name='1'></a>__::base64::encode__ ?__\-maxlen__ *maxlen*? ?__\-wrapchar__ *wrapchar*? *string*
50
51    Base64 encodes the given binary *string* and returns the encoded result\.
52    Inserts the character *wrapchar* every *maxlen* characters of output\.
53    *wrapchar* defaults to newline\. *maxlen* defaults to __76__\.
54
55    *Note* that if *maxlen* is set to __0__, the output will not be
56    wrapped at all\.
57
58    *Note well*: If your string is not simple ascii you should fix the string
59    encoding before doing base64 encoding\. See the examples\.
60
61    The command will throw an error for negative values of *maxlen*, or if
62    *maxlen* is not an integer number\.
63
64  - <a name='2'></a>__::base64::decode__ *string*
65
66    Base64 decodes the given *string* and returns the binary data\. The decoder
67    ignores whitespace in the string\.
68
69# <a name='section2'></a>EXAMPLES
70
71    % base64::encode "Hello, world"
72    SGVsbG8sIHdvcmxk
73
74    % base64::encode [string repeat xyz 20]
75    eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
76    eHl6eHl6eHl6
77    % base64::encode -wrapchar "" [string repeat xyz 20]
78    eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
79
80    # NOTE: base64 encodes BINARY strings.
81    % set chemical [encoding convertto utf-8 "C\u2088H\u2081\u2080N\u2084O\u2082"]
82    % set encoded [base64::encode $chemical]
83    Q+KCiEjigoHigoBO4oKET+KCgg==
84    % set caffeine [encoding convertfrom utf-8 [base64::decode $encoded]]
85
86# <a name='section3'></a>Bugs, Ideas, Feedback
87
88This document, and the package it describes, will undoubtedly contain bugs and
89other problems\. Please report such in the category *base64* of the [Tcllib
90Trackers](http://core\.tcl\.tk/tcllib/reportlist)\. Please also report any ideas
91for enhancements you may have for either package and/or documentation\.
92
93When proposing code changes, please provide *unified diffs*, i\.e the output of
94__diff \-u__\.
95
96Note further that *attachments* are strongly preferred over inlined patches\.
97Attachments can be made by going to the __Edit__ form of the ticket
98immediately after its creation, and then using the left\-most button in the
99secondary navigation bar\.
100
101# <a name='keywords'></a>KEYWORDS
102
103[base64](\.\./\.\./\.\./\.\./index\.md\#base64),
104[encoding](\.\./\.\./\.\./\.\./index\.md\#encoding)
105
106# <a name='category'></a>CATEGORY
107
108Text processing
109
110# <a name='copyright'></a>COPYRIGHT
111
112Copyright &copy; 2000, Eric Melski
113Copyright &copy; 2001, Miguel Sofer
114