varint-wasm package icon
jwerle/varint-wasm
Public
wasmer run jwerle/varint-wasm

varint-wasm

A varint implementation for WebAssembly (WASM) written in ZZ that implements an Abstract Encoding interface.

Installation

Node

$ npm install @little-core-labs/varint-wasm

WAPM

$ wapm install jwerle/varint-wasm

Usage

const varint = require('varint-wasm')

// wait for module to be ready if loading in a browser environment
varint.ready(() => {
  const encoded = varint.encode(64 * 1024)
  console.log(encoded) // <Buffer 80 80 04>

  const decoded = varint.decode(encoded)
  console.log(decoded) // 65536
})

API

buffer = encode(number[, buffer[, offset]])

Encode a number optionally into buffer at an optionally specified offset.

number = decode(buffer[, offset])

Decode an input buffer into an integer optionally an optionally specified offset.

promise = ready(callback)

Returns a promise that resolves or rejects when the WebAssembly exports are loading. In some cases, this may happen synchronously when this module is loaded.

await b64.ready()

Limits

Max Integer

Because 32-bit integers are only supported in WASM at the time of writing, you can only encode numbers up 2**31 -1.

Initial Memory

By default, this module allocates 2 pages of memory for the WebAssembly module. That is 2 * 64 * 1024 bytes.

Maximum Memory

This module allows at most 256 pages of memory. That is 256 * 64 * 1024 bytes.

See Also

License

MIT

A varint implementation written in ZZ compiled to WASM


Github
More packages
wasm in Go
Kaiya Xiong
Kaiya Xiong
Kaiya Xiong
Kaiya Xiong
wasm in Go
wasm in Go
wasm in Go
WalletD WASM
Karl Buys
Karl Buys
Karl Buys
Karl Buys
WalletD WASM
Devin
Devin
Devin
Devin
WalletD WASM
Amulya
Amulya
Amulya
Amulya
wasm in Go
Wasm Project
jazzandrock avatar
jazzandrock
jazzandrock avatar
jazzandrock

Making software universally accessible