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

erlpack

v0.1.4

Published

Erlpack is a fast encoder and decoder for the Erlang Term Format (version 131) for JavaScript

Downloads

8,029

Readme

Erlpack

Erlpack is a fast encoder and decoder for the Erlang Term Format (version 131) for Python and JavaScript.

JavaScript

Things that can be packed:

  • [X] Null
  • [X] Booleans
  • [X] Strings
  • [ ] Atoms
  • [X] Unicode Strings
  • [X] Floats
  • [X] Integers
  • [ ] Longs
  • [ ] Longs over 64 bits
  • [X] Objects
  • [X] Arrays
  • [ ] Tuples
  • [ ] PIDs
  • [ ] Ports
  • [ ] Exports
  • [ ] References

How to pack:

let erlpack = require("erlpack");

packed = erlpack.pack({'a': true, 'list': ['of', 3, 'things', 'to', 'pack']});

How to unpack:

Note: Unpacking requires the binary data be a Uint8Array or Buffer. For those using electron/libchromium see the gotcha below.

let erlpack = require("erlpack");

let unpacked = null;
let packed = new Buffer('', 'binary');
try  {
    unpacked = erlpack.unpack(packed);
}
catch (e) {
    // got an exception parsing
}

Libchromium / Electron Gotcha

Some versions of libchromium replace the native data type backing TypedArrays with a custom data type called blink::WebArrayBuffer. To keep erlpack' dependencies simple this data type is not supported directly. If you're using Electron / Libchromium you need to convert the blink::WebArrayBuffer into a node::Buffer before passing to erlpack. You will need to add this code into your native package somewhere:

v8::Local<v8::Value> ConvertToNodeBuffer(const v8::Local<v8::Object>& blinkArray)
{
    if (node::Buffer::HasInstance(blinkArray)) {
        return blinkArray;
    }
    else if (blinkArray->IsArrayBufferView()) {
        auto byteArray = v8::ArrayBufferView::Cast(*blinkArray);
        return node::Buffer::Copy(v8::Isolate::GetCurrent(), (const char*)byteArray->Buffer()->GetContents().Data(), byteArray->ByteLength()).ToLocalChecked();
    }
    
    return v8::Local<v8::Primitive>(v8::Null(v8::Isolate::GetCurrent()));
}

Then in JavaScript something like:

let packed = NativeUtils.convertToNodeBuffer(new Uint8Array(binaryPayload));
// unpack now using erlpack.unpack(packed)

Python

Things that can be packed:

  • [X] None
  • [X] Booleans
  • [X] Strings
  • [X] Atoms
  • [X] Unicode Strings
  • [X] Floats
  • [X] Integers
  • [X] Longs
  • [ ] Longs over 64 bits
  • [X] Dictionaries
  • [X] Lists
  • [X] Tuples
  • [X] User Types (via an encode hook)
  • [ ] PIDs
  • [ ] Ports
  • [ ] Exports
  • [ ] References

How to pack:

from erlpack import pack

packed = pack(["thing", "to", "pack"])

How to unpack:

from erlpack import unpack

unpacked = unpack(packed)

How to pack an atom:

from erlpack import Atom, pack

packed = pack(Atom('hello'))

How to use an encode hook.

from erlpack import ErlangTermEncoder

def encode_hook(obj):
    if isinstance(obj, datetime.datetime):
        return obj.isoformat()

encoder = ErlangTermEncoder(encode_hook=encode_hook)
packed = encoder.pack(datetime.datetime(2015, 12, 25, 12, 23, 55))

How to make custom types packable.

from erlpack import pack, Atom

class User(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __erlpack__(self):
        return {
            Atom('name'): self.name,
            Atom('age'): self.age
        }

u = User(name='Jake', age=23)
packed = pack(u)

Go (golang)

Discord has moved away from Go internally and so we do not maintain a version of erlpack in Go ourselves. However, all is not lost!, please check out: https://github.com/JakeMakesStuff/go-erlpack