The code.lua 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 RFC 2045, URL escaping is described in RFC 2396.
socket.code.base64(content, single)
Applies the Base 64 content coding to a string.
Content is the string to be encoded. If single is set to anything but nil, the output is returned as a single line, otherwise the function splits the content into 76 character long lines after encoding.
The function returns the encoded string.
code = socket.code.base64("diego:password") -- code = "ZGllZ286cGFzc3dvcmQ="
socket.code.unbase64(content)
Removes the Base 64 content coding from a string.
Content is the string to be decoded.
The function returns the decoded string.
socket.code.escape(content)
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.
Content is the string to be encoded.
The function returns the encoded string.
code = socket.code.escape("/#?;") -- code = "%2f%23%3f%3b"
socket.code.unescape(content)
Removes the URL escaping content coding from a string.
Content is the string to be decoded.
The function returns the decoded string.
socket.code.hexa(content)
Applies the hexadecimal content coding to a string. Each byte is encoded as the byte hexadecimal representation of its integer value.
Content is the string to be encoded.
The function returns the encoded string.
code = socket.code.hexa("\16\32\255") -- code = "1020ff"
socket.code.unhexa(content)
Removes the hexadecimal content coding from a string.
Content is the string to be decoded.
The function returns the decoded string.