Socket
Socket
Sign inDemoInstall

buffer-write

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    buffer-write

Write to a buffer without maintaining an offset or knowing its length


Version published
Weekly downloads
7
Maintainers
1
Install size
22.0 kB
Created
Weekly downloads
 

Readme

Source

buffer-write

Build Status Coverage Status

Write to a buffer without maintaining an offset or knowing its length.

  • This module tries to mirror Buffer methods for simplicity.
  • Supports writing 64-bit values at 52-bit precision (JavaScript safe integer maximum).

Install

npm install buffer-write

Usage

var Writer = require('buffer-write');

// Normal method
var writer = new Writer()
writer.write('a')
writer.fill(1, 3)
writer.writeInt8(0x72)
writer.toBuffer(); // <Buffer 61 01 01 01 72>

// Chain method
Writer()
  .writeUInt16BE(0x7623)
  .write(new Buffer([1, 2, 3, 4]), 2)
  .writeUInt16LE(0x1800)
  .toBuffer(); // <Buffer 76 23 01 02 00 18>

API

NOTE: There is no concept of offset when using this module as values are effectively appended to each other.

write[U]Int8(value), write[U]{16,32,64}{BE,LE}(value)

Write an integer of the specified size and endian format. A RangeError will be thrown for any out of range values. 64-bit integer methods will only accept 52-bit integer values.

writeFloat{BE,LE}(value), writeDouble{BE,LE}(value)

Write a floating point number of the specified size and endian format.

write(string, [length], [encoding])

Write a string of specified length and encoding.

write(buffer, [start], [end])

Write a buffer or part of a buffer.

fill(value, length)

Fill with length repetitions of the specified value.

length

The number of bytes currently written.

copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])

Write our values into an existing buffer.

toBuffer()

Create a new buffer and write our values.

License

MIT

FAQs

Last updated on 19 Jun 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc