1.0.2 • Published 8 years ago

binaryreader v1.0.2

Weekly downloads
3
License
GPL
Repository
github
Last release
8 years ago

BinaryReader

A javascript object for simplifying the sequential reading of binary data.

Usage

Properties

Number of bytes in the file:

reader.byteLength;

Current read position in bytes:

reader.bytePos;

Methods

Create new BinaryReader:

// dataSource: URL, ArrayBuffer, Blob, or File object to be read
// callback: function called for reading data after data has been loaded
// Use the callback to ensure that the data has been recieved before attempting to read.
// Otherwise check byteLength before attempting to read data.
var reader = new BinaryReader(dataSource, callback);

Read bytes from the file:

// numBytes: integer number of bytes to read
// radix: base of the value returned.
var bytes = reader.nextBytes(numBytes[, radix]);

Move the read position:

// numBytes: integer number of bytes to move; negative integers move backwards
reader.move(numBytes);
// NOTE: the read position is tracked internally so 
// there is no need to call move() after reading data

Set the read position:

// pos: location to set the read position to
reader.setReadPos(pos);

Potential Future Features

  • Support for bit level reads