Node Buffer Reader
Make reading data from a binary buffer easily.
Install
npm install buffer-reader
Usage
var BufferReader = ;var reader = buffer;// Read next N bytes as stringvar str = reader;// Read next N bytes as buffervar buf = reader;// Read next 2 bytes as Int16LEvar i = reader;// Read next 8 bytes as DoubleLEvar d = reader;// Get all rest bytes as buffervar rest = reader;// OutOfBound will raise exceptiontryreader;cache(e) {// handle exception}// Append buffer to readerreader;// Read againreader;
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.