脚本开发

模块 ringo / base64

Base64 编码和解码二进制数据和字符串。

Example

>> var base64 = require('ringo/base64');
>> var enc = base64.encode('Hello World!', 'ISO-8859-15');
>> print(enc);
'SGVsbG8gV29ybGQh'
>> print(base64.decode(enc, 'ISO-8859-15'));
Hello World!

Functions


decode (str, encoding)

将Base64编码的字符串解码为字符串或字节数组。

Parameters

String str

the Base64 encoded string

String encoding

the encoding to use for the return value. Defaults to 'utf8'. Use 'raw' to get a ByteArray instead of a string.

Returns

String|ByteArray

the decoded string or ByteArray


encode (str, encoding)

将字符串或二进制编码为 Base64 编码的字符串

Parameters

String|Binary str

a string or binary

String encoding

optional encoding to use if first argument is a string. Defaults to 'utf8'.

Returns

String

the Base64 encoded string