Ascii85 (Base85) Encoding/Decoding
Ascii85, also called Base85, is a form of binary-to-text encoding. By using five ASCII characters to represent four bytes of binary data, it is more efficient than uuencode or Base64, which use four characters to represent three bytes of data. See ascii85 wikipedia page for more details.
This node module provides straight forward APIs to encode/decode data in ascii85 encoding. Both string
and Buffer
are accepted by encode()
and decode()
functions. The return value of both functions is a Buffer
for better performance.
Install
Install ascii85
through npm
.
npm install --save ascii85
Usage
var ascii85 = ;var buf = ascii85; buf === 'ARTY*'; // trueascii85 === 'easy'; // true
API
encode(data, [options])
Encode a string or Buffer
.
data
is a string or aBuffer
.options
is optional. If it's provided, it can be an array of character or an option object.- Return a
Buffer
with encoded data.
Here is a sample.
var ascii85 = ;var buf; // Most common use.buf = ascii85; // Provide an array of characters to encode the string.// The array must have 85 elements. It's useful to work// with a customized ascii85 encoding, e.g. ZeroMQ flavor.buf = ascii85; buf = ascii85;
decode(str, [table])
Decode a ascii85-encoded string or Buffer
.
str
is a string or aBuffer
. All invalid characters will be discarded. Ifstr
starts with<~
, it must have~>
at the end. Otherwise, an error will be thrown.table
is a sparse array to map char code to decoded value for decoding.- Return a
Buffer
with decoded data. - Invalid characters are ignored silently.
Here is a sample.
var ascii85 = ;var data; // Most common use.data = ascii85; // Spaces can be omitted automatically.data = ascii85; // '<~' and '~>' can be trimmed properly.data = ascii85; // Provide a sparse array to map char code to decode value.ascii85;
Ascii85(options)
Construct a new codec object. It can store customized options for every encode
/decode
.
var Ascii85 = Ascii85; // PostScript always uses delimiter.var PostScript = delimiter: true; PostScript === '<~ARTY*~>'; // true
ZeroMQ
A specialized codec for ZeroMQ which uses different charset.
var ZeroMQ = ZeroMQ;ZeroMQ === 'wNPU9'; // true
PostScript
A specialized codec for PostScript which always uses delimiter.
var PostScript = PostScript;PostScript === '<~ARTY*~>'; // true
License
This module is licensed under the MIT license that can be found in the LICENSE file.