Giter Site home page Giter Site logo

node-buffer-reader's Introduction

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 [email protected]; All rights reserved.

node-buffer-reader's People

Contributors

joshperry avatar villadora avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.