npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ascii85

v1.0.2

Published

Ascii85 (a.k.a. base85) encoding/decoding.

Downloads

24,095

Readme

Ascii85 (Base85) Encoding/Decoding

Build Status

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 = require('ascii85');
var buf = ascii85.encode('easy');

buf.toString() === 'ARTY*';                // true
ascii85.decode(buf).toString() === 'easy'; // true

API

encode(data, [options])

Encode a string or Buffer.

  • data is a string or a Buffer.
  • 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 = require('ascii85');
var buf;

// Most common use.
buf = ascii85.encode('easy');

// 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.encode('easy', ['0', '1', '2', ...]);

buf = ascii85.encode('easy', {
	table: [...],     // an array of characters to encode the string
	delimiter: false, // result will be surrounded by '<~' and '~>'
	groupSpace: false // group spaces by 'u'
});

decode(str, [table])

Decode a ascii85-encoded string or Buffer.

  • str is a string or a Buffer. All invalid characters will be discarded. If str 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 = require('ascii85');
var data;

// Most common use.
data = ascii85.decode('ARTY*');

// Spaces can be omitted automatically.
data = ascii85.decode('A  R  T  Y  *');

// '<~' and '~>' can be trimmed properly.
data = ascii85.decode('<~ARTY*~>');

// Provide a sparse array to map char code to decode value.
ascii85.decode('ARTY*', [...]);

Ascii85(options)

Construct a new codec object. It can store customized options for every encode/decode.

var Ascii85 = require('ascii85').Ascii85;

// PostScript always uses delimiter.
var PostScript = new Ascii85({
	delimiter: true
});

PostScript.encode('easy').toString() === '<~ARTY*~>'; // true

ZeroMQ

A specialized codec for ZeroMQ which uses different charset.

var ZeroMQ = require('ascii85').ZeroMQ;
ZeroMQ.encode('easy').toString() === 'wNPU9'; // true

PostScript

A specialized codec for PostScript which always uses delimiter.

var PostScript = require('ascii85').PostScript;
PostScript.encode('easy').toString() === '<~ARTY*~>'; // true

License

This module is licensed under the MIT license that can be found in the LICENSE file.