base-256

1.3.0 • Public • Published

base-256

encode and decode base256 encoding as gnu-tar does (supported range is -9007199254740991 to 9007199254740991).

npm install base-256

Build Status

How it is different than buffer.writeInt32BE

It's a variable length encoding.

Usage

const { encode, decode } = require('base-256')
 
const buf = new Buffer(12)
encode(buf, 2147483647)
// buf here is <Buffer 80 7f ff ff ff
 
const decodedValue = decode(buf)
// decodedValue is 2147483647

API

base256.encode(buffer, num) Pass a buffer and the number that needs to be encoded. The number will be encoded into that buffer.

base256.decode(buf, [offset]) Decode a number from a buffer. If an offset is passed as the second argument the buf should be decoded at that byte offset. The byte offset defaults to 0.

Errors

  • Throws TypeError if the input yields a number that is out of range (-9007199254740991 to 9007199254740991).
  • Throws TypeError if the input is of not correct type.
  • Throws TypeError if the output of decoded value of encoded buffer goes out of range -9007199254740991 to 9007199254740735.

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i base-256

      Weekly Downloads

      0

      Version

      1.3.0

      License

      MIT

      Unpacked Size

      11.5 kB

      Total Files

      8

      Last publish

      Collaborators

      • aks-