1base64(n)            Text encoding & decoding binary data            base64(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       base64 - base64-encode/decode binary data
9

SYNOPSIS

11       package require Tcl  8
12
13       package require base64  ?2.4.2?
14
15       ::base64::encode ?-maxlen maxlen? ?-wrapchar wrapchar? string
16
17       ::base64::decode string
18
19______________________________________________________________________________
20

DESCRIPTION

22       This  package provides procedures to encode binary data into base64 and
23       back.
24
25       ::base64::encode ?-maxlen maxlen? ?-wrapchar wrapchar? string
26              Base64 encodes the given binary string and returns  the  encoded
27              result.  Inserts  the character wrapchar every maxlen characters
28              of output. wrapchar defaults to newline. maxlen defaults to 76.
29
30              Note that if maxlen is set to 0, the output will not be  wrapped
31              at all.
32
33              Note well: If your string is not simple ascii you should fix the
34              string encoding before doing base64 encoding. See the examples.
35
36              The command will throw an error for negative values  of  maxlen,
37              or if maxlen is not an integer number.
38
39       ::base64::decode string
40              Base64  decodes  the  given  string and returns the binary data.
41              The decoder ignores whitespace in the string.
42

EXAMPLES

44              % base64::encode "Hello, world"
45              SGVsbG8sIHdvcmxk
46
47
48
49              % base64::encode [string repeat xyz 20]
50              eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
51              eHl6eHl6eHl6
52              % base64::encode -wrapchar "" [string repeat xyz 20]
53              eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
54
55
56
57              # NOTE: base64 encodes BINARY strings.
58              % set chemical [encoding convertto utf-8 "C\u2088H\u2081\u2080N\u2084O\u2082"]
59              % set encoded [base64::encode $chemical]
60              Q+KCiEjigoHigoBO4oKET+KCgg==
61              % set caffeine [encoding convertfrom utf-8 [base64::decode $encoded]]
62
63

BUGS, IDEAS, FEEDBACK

65       This document, and the package it describes, will  undoubtedly  contain
66       bugs  and other problems.  Please report such in the category base64 of
67       the  Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please
68       also  report any ideas for enhancements you may have for either package
69       and/or documentation.
70
71       When proposing code changes, please provide unified diffs, i.e the out‐
72       put of diff -u.
73
74       Note  further  that  attachments  are  strongly  preferred over inlined
75       patches. Attachments can be made by going  to  the  Edit  form  of  the
76       ticket  immediately  after  its  creation, and then using the left-most
77       button in the secondary navigation bar.
78

KEYWORDS

80       base64, encoding
81

CATEGORY

83       Text processing
84
86       Copyright (c) 2000, Eric Melski
87       Copyright (c) 2001, Miguel Sofer
88
89
90
91
92tcllib                               2.4.2                           base64(n)
Impressum