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

buffer-writer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer-writer

a fast, efficient buffer writer

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8M
decreased by-20.14%
Maintainers
1
Weekly downloads
 
Created

What is buffer-writer?

The buffer-writer package is a Node.js module that provides a way to write values to a Buffer with automatic buffer management. It allows for writing various types of data, such as integers, strings, and floating-point numbers, in a binary format to a buffer. This can be particularly useful when dealing with binary protocols or when you need to serialize data for storage or network transmission.

What are buffer-writer's main functionalities?

Writing integers

This feature allows writing 8-bit, 16-bit, and 32-bit integers to a buffer. The 'BE' and 'LE' suffixes indicate whether the integer should be written in big-endian or little-endian format.

const BufferWriter = require('buffer-writer');
const writer = new BufferWriter();
writer.writeInt8(0x68);
writer.writeInt16BE(0x1234);
writer.writeInt32LE(0x12345678);
const buffer = writer.getBuffer();

Writing floating-point numbers

This feature allows writing 32-bit and 64-bit floating-point numbers to a buffer. Similar to integers, the 'BE' and 'LE' suffixes indicate the endianness.

const BufferWriter = require('buffer-writer');
const writer = new BufferWriter();
writer.writeFloatBE(3.14);
writer.writeDoubleLE(3.141592653589793);
const buffer = writer.getBuffer();

Writing strings

This feature allows writing strings to a buffer. It supports writing standard strings and null-terminated strings, which are commonly used in C-style string handling.

const BufferWriter = require('buffer-writer');
const writer = new BufferWriter();
writer.writeString('Hello, World!');
writer.writeStringZero('Null-terminated string.');
const buffer = writer.getBuffer();

Buffer management

This feature allows for managing the buffer by moving the write position. In this example, the 'rewind' method is used to move the write position back, allowing overwriting of previously written data.

const BufferWriter = require('buffer-writer');
const writer = new BufferWriter();
writer.writeUInt8(0xff);
writer.rewind(1);
writer.writeUInt8(0x7f);
const buffer = writer.getBuffer();

Other packages similar to buffer-writer

Keywords

FAQs

Package last updated on 07 Nov 2018

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