0.0.8 • Published 10 years ago

buffer-wrapper v0.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

buffer-wrapper

Wrapper for Buffer class in Nodejs which keeps track of position and supports arrays.

Installation

npm install buffer-wrapper

Usage

A buffer is wrapped as follows

var bwrapper = require('buffer-wrapper');
var wrapped = new bwrapper(new Buffer());

seek

Seek to a particular octet position in the buffer.

wrapped.seek(10);

reset

Reset wrapper position to a the beginning.

wrapped.reset();

getOffset

Return the wrapper position.

wrapped.getOffset();

reading

Read using basic format x (e.g. UInt8), by calling function readx() (for single units) or readxArray() (for an array of units), from the present position. All buffer read calls are supported, and underlying position is advanced according to size of format x and/or array length.

wrapped.readUInt8(); // Read a single UInt8 format units at present position
wrapped.readUInt8Array(); // Read an array of UInt8 format units at present position

writing

Exact same as for reading, only substitute with write term.

wrapped.writeUInt8(a_single_number); // Write a single UInt8 format units at present position
wrapped.writeUInt8Array(an_array); // Read an array of UInt8 format units at present position

buffer

Reading a buffer through the wrapper, where the content from the wrapped buffer is copied and the offset is advanced.

var buf = wrapped.readBuffer(number_of_octets);

Writing a buffer through the wrapper, where the content from the source buffer is copied and the offset in the wrapper is advanced.

var buf = new Buffer([1,2,3]):
wrapped.writeBuffer(buf);

Tests

npm test

Release History

* 0.0.4 20.07.2014
* 0.0.5 31.07.2014
* 0.0.8 01.08.2014
0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago