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

buffer-reader

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-reader

a reader for nodejs buffer

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
565
decreased by-21.42%
Maintainers
1
Weekly downloads
 
Created
Source

Node Buffer Reader

Make reading data from a binary buffer easily.

Build Status

Install

npm install buffer-reader

Usage

var BufferReader = require('buffer-reader');
var reader = new BufferReader(buffer);

// Read next N bytes as string
var str = reader.nextString(10);

// Read next N bytes as buffer
var buf = reader.nextBuffer(10);

// Read next 2 bytes as Int16LE
var i = reader.nextInt16LE();


// Read next 8 bytes as DoubleLE
var d = reader.nextDoubleLE();

// Get all rest bytes as buffer
var rest = reader.restAll();

// OutOfBound will raise exception
try {
    reader.nextString(1);
}cache(e) {
    //  handle exception
}

// Append buffer to reader
reader.append(newbuffer);

// Read again
reader.nextString(1);

APIs

new BufferReader([buffer])

Create a new reader, if no buffer provided, a empty buffer will be used.

append(buffer)

Append new buffer to the end of current reader

tell()

Return current position of the reader

seek(pos)

Set new position of the reader, if the pos is invalid, an exception will be raised

move(offset)

Move the position of reader by offset, offset can be negative; it can be used to skip some bytes

restAll()

Get all the remaining bytes as a Buffer

nextBuffer(length)

Read a buffer with specified length

nextString(length, [encoding])

Read next length of bytes as String, encoding default is 'utf8'

next(Int8|UInt8)[(Int16|UInt16|Int32|UInt32|Float|Double)(LE|BE)]()

Read next bytes as given types, the value is just as the same format Buffer in nodejs doc.

License

(The BSD License)

Copyright (c) 2013, Villa.Gao jky239@gmail.com; All rights reserved.

FAQs

Package last updated on 10 Feb 2015

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