0.0.2 • Published 10 years ago

buffer-read v0.0.2

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

buffer-read

Build Status Coverage Status

Read values from a buffer without maintaining an offset. Useful when you don't want to maintain an offset yourself.

  • This module tries to mirror Buffer methods for simplicity.
  • Supports reading 64-bit values at 52-bit precision (JavaScript safe integer maximum).

Install

npm install buffer-read

Usage

var Reader = require('buffer-read');

var reader = new Reader(new Buffer('6101010172010203', 'hex'));
reader.toString(1); // 'a'
reader.offset += 3; // Skip over 3 bytes
reader.readInt8()   // 0x72
reader.slice(3)     // <Buffer 01 02 03>

API

readUInt8(), readU{16,32,64}{BE,LE}()

Read an integer of the specified size and endian format.

readFloat{BE,LE}(), readDouble{BE,LE}()

Read a floating point number of the specified size and endian format.

toString(encoding, length)

Read a string of specified length and encoding.

slice(length)

Create a slice of the buffer.

offset

The current byte offset.

copy(targetBuffer, length, targetStart)

Copy data into another buffer.

License

MIT