Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@node-lightning/bufio

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-lightning/bufio

Buffer IO utilities

  • 0.21.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Utilities for Buffer IO

CircleCI codecov

Usage:

npm install @node-lightning/bufio
const { BufferReader, BufferWriter } = require("@node-lightning/bufio");

// write arbitrary length data
const writer = new BufferWriter();
writer.writeUInt8(1);
writer.writeUInt16BE(2);
writer.writeUInt32BE(3);
writer.writeBytes(Buffer.from([4]));
let buffer = writer.toBuffer();

// read values
const reader = new BufferReader(buffer);
console.log(buffer.readUInt8());
console.log(buffer.readUInt16BE());
console.log(buffer.readUInt32BE());
console.log(buffer.readBytes());

BufferReader

This class wraps an existing Buffer and allows reading data from the Buffer. This class includes

  • position: number - the current buffer cursor position

  • eof: bool - whether the current position is at the end of the buffer

  • buffer: Buffer - the underlying buffer

  • lastReadBytes - number of bytes last read from the buffer

  • readUInt8(): number - reads 1 byte

  • readUInt16LE(): number - reads 2 bytes as 16-bit little-endian unsigned integer

  • readUInt16BE(): number - reads 2 bytes as 16-bit big-endian unsigned integer

  • readUInt32LE(): number - reads 4 bytes as 32-bit little-endian unsigned integer

  • readUInt32BE(): number - reads 4 bytes as 32-bit big-endian unsigned integer

  • readUInt64LE(): bigint - reads 8 bytes as 64-bit little-endian unsigned integer

  • readUInt64BE(): bigint - reads 8 bytes as 64-bit big-endian unsigned integer

  • readVarUint(): bigint - reads a variable length integer as defined in the Bitcoin protocol docs

  • readBigSize(): bigint - reads a variable length integer as defined in the Lightning Network

  • readBytes([len]): Buffer - reads the optionally specified number of bytes. If no length is supplied, it reads to the end of the buffer.

BufferWriter

This class can accept an existing Buffer and write to. When used in this mode the Buffer length is fixed and writes that overflow the Buffer will throw an execption.

This class can intenrally manage a Buffer and will automatically expand to fit the data footprint required. At the end of writing, .toBuffer must be called to obtain the underlying Buffer.

  • writeUInt8(number): undefined - writes 1 byte
  • writeUInt16LE(number): undefined - writes a number as a 16-bit little-endian unsigned integer
  • writeUInt16BE(number): undefined - writes a number as a 16-bit big-endian unsigned integer
  • writeUInt32LE(number): undefined - writes a number as a 32-bit little-endian unsigned integer
  • writeUInt32BE(number): undefined - writes a number as a 32-bit big-endian unsigned integer
  • writeUInt64LE(number): undefined - writes a number as a 64-bit little-endian unsigned integer
  • writeUInt64BE(number): undefined - writes a number as a 64-bit big-endian unsigned integer
  • writeBytes(buffer): undefined - writes the supplied buffer to the cursor buffer

FAQs

Package last updated on 18 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc