Make reading data from a binary buffer easily.
npm install buffer-reader
varBufferReader=require('buffer-reader');varreader=newBufferReader(buffer);// Read next N bytes as stringvarstr=reader.nextString(10);// Read next N bytes as buffervarbuf=reader.nextBuffer(10);// Read next 2 bytes as Int16LEvari=reader.nextInt16LE();// Read next 8 bytes as DoubleLEvard=reader.nextDoubleLE();// Get all rest bytes as buffervarrest=reader.restAll();// OutOfBound will raise exceptiontry{reader.nextString(1);}cache(e){// handle exception}// Append buffer to readerreader.append(newbuffer);// Read againreader.nextString(1);Create a new reader, if no buffer provided, a empty buffer will be used.
Append new buffer to the end of current reader
Return current position of the reader
Set new position of the reader, if the pos is invalid, an exception will be raised
Move the position of reader by offset, offset can be negative; it can be used to skip some bytes
Get all the remaining bytes as a Buffer
Read a buffer with specified length
Read next length of bytes as String, encoding default is 'utf8'
Read next bytes as given types, the value is just as the same format Buffer in nodejs doc.
(The BSD License)
Copyright (c) 2013, Villa.Gao jky239@gmail.com; All rights reserved.
