aboutsummaryrefslogtreecommitdiff
path: root/doc/code.html
blob: 45fd21a0a8575d57ff9fa6df57a588d7d7621dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>LuaSocket: Network support for the Lua language</title>
<link rel="stylesheet" href="reference.css" type="text/css">
</head>

<body>

<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<div class=header>
<hr>
<center>
<table summary="LuaSocket logo">
<tr><td align=center><a href="http://www.lua.org">
<img border=0 alt="LuaSocket" src="luasocket.png">
</a></td></tr>
<tr><td align=center valign=top>Network support for the Lua language
</td></tr>
</table>
<p class=bar>
<a href="home.html">home</a> &middot;
<a href="home.html#download">download</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a> 
</p>
</center>
<hr>
</div>

<!-- code +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<h2 id=code>Code</h2> 

<p>
The <tt>code.lua</tt> module  offers routines to convert  back and forth
some common types of content encoding, including Base 64 and URL
escaping. Base 64 is described in
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2045.txt">RFC
2045</a>,
URL escaping is described in 
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC
2396</a>.
</p>

<!-- base64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id="base64">
socket.code.<b>base64(</b>content, single<b>)</b>
</p>

<p class=description>
Applies the Base  64 content coding to a string.
</p>

<p class=parameters>
<tt>Content</tt> is the string to be encoded. 
If  <tt>single</tt> is set  to  anything  
but <tt>nil</tt>, the output is returned as a single 
line, otherwise the function splits the content into 76 character long
lines after encoding.
</p>

<p class=result>
The function returns the encoded string.
</p>

<pre class=example>
code = socket.code.base64("diego:password")
-- code = "ZGllZ286cGFzc3dvcmQ="
</pre>

<!-- unbase64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id="unbase64">
socket.code.<b>unbase64(</b>content<b>)</b>
</p>

<p class=description>
Removes the Base 64 content coding from a string.
</p>

<p class=parameters>
<tt>Content</tt> is the string to be decoded.
</p>

<p class=result>
The function returns the decoded string.
</p>

<!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id="escape">
socket.code.<b>escape(</b>content<b>)</b>
</p>

<p class=description>
Applies the URL escaping content coding to a string
Each byte is encoded as a percent character followed
by the two byte hexadecimal representation of its integer 
value.
</p>

<p class=parameters>
<tt>Content</tt> is the string to be encoded.
</p>

<p class=result>
The function returns the encoded string.
</p>

<pre class=example>
code = socket.code.escape("/#?;")
-- code = "%2f%23%3f%3b"
</pre>

<!-- unescape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id="unescape">
socket.code.<b>unescape(</b>content<b>)</b>
</p>

<p class=description>
Removes  the   URL   escaping    content   coding   from   a string.
</p>

<p class=parameters>
<tt>Content</tt> is the string to be decoded.
</p>

<p class=return>
The function returns the decoded string. 
</p>

<!-- hexa +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id="hexa">
socket.code.<b>hexa(</b>content<b>)</b>
</p>

<p class=description>
Applies the  hexadecimal content coding to a string.
Each byte  is encoded as  the byte hexadecimal
representation of its integer value. <p>
</p>

<p class=parameters>
<tt>Content</tt> is the string to be encoded.
</p>

<p class=return>
The function returns the encoded string. 
</p>

<pre class=example>
code = socket.code.hexa("\16\32\255")
-- code = "1020ff"
</pre>

<!-- unhexa +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id="unhexa">
socket.code.<b>unhexa(</b>content<b>)</b>
</p>

<p class=description>
Removes the hexadecimal content coding from a string.
</p>

<p class=parameters> 
<tt>Content</tt> is the string to be decoded.
</p>

<p class=return>
The function returns the decoded string.
</p>

<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<div class=footer>
<hr>
<center>
<p class=bar>
<a href="home.html">home</a> &middot;
<a href="home.html#down">download</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
</p>
<p>
<small>
Last modified by Diego Nehab on <br>
Sat Aug 9 01:00:41 PDT 2003
</small>
</p>
</center>
</div>

</body>
</html>