bytewriter
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

node-bytewriter

NPM version Build Status Try it on gitpod PrismarineJS Discord

A simple zero-dep binary byte stream implementation for Node.js with support for reading and writing numbers, strings, and varints (zigzag or unsigned) in both little and big endian encoding.

Install

npm install bytewriter

Usage

Simple example to create a new empty Buffer stream:

const ByteStream = require('bytewriter')
const stream = new ByteStream()
stream.writeStringNT("hello world!") // write a string with a null term at end
const buffer = stream.getBuffer()
console.assert(buffer.equals(Buffer.from('hello world!\0'))

Load an existing one:

const BinaryStream = require('bytewriter')
const stream = new BinaryStream(Buffer.from('10 10 10', 'hex'))
const a = stream.readUInt8()
const b = stream.readUInt16()

API

See the typescript types here for the full API

License

MIT

Package Sidebar

Install

npm i bytewriter

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

20.2 kB

Total Files

13

Last publish

Collaborators

  • extremeheat