bint8array
Uint8Array utils for parity with Buffers
Last updated 4 years ago by chm-diederichs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install bint8array 
SYNC missed versions from official npm registry.

bint8array

Emulate core Buffer methods for Uint8Arrays

Usage

npm i -s bint8array
const bint = require('bint8array')

const buf = bint.allocUnsafe(32)
const hex = bint.fromString('776f726b7320696e2062726f7773657220746f6f21', 'hex')
const b64 = bint.fromString('deadbeef11247', 'hex')
const text = bint.toString(hex, 'utf8')

console.log(text)
// works in browser too!

console.log(bint.compare(Buffer.alloc(2), Buffer.alloc(2, 1)))
// -1

API

bint.toString(buf, [enc])

Decode bytes to a string according to the given encoding enc. Options for enc are ascii, utf8, utf-8, hex and base64.

bint.fromString(string, [enc])

Encode a string to binary according to the given encoding enc. Options for enc are ascii, utf8, utf-8, hex and base64.

Note that for hex encoding, if the string is not of even length, the last character shall be ignore. This is in keeping with the behaviour of the core Buffer.from method.

bint.compare(buf1, buf2)

Compare two Uint8Arrays bytewise. Returns -1 if buf1 is lesser, 1 if buf2 is greater and 0 if and only if buf1[i] ==== buf2[i] for all len = buf1.byteLength = buf2.byteLength.

bint.concat(arrrayOfBuffers)

Concatenate an array of Uint8Arrays into a single Uint8Array.

bint.allocUnsafe(size)

Create a new Uint8Array of a given size.

Current Tags

  • 1.1.3                                ...           latest (3 years ago)

7 Versions

  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 4
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |