2.1.0 • Published 5 years ago

bitreader-v2 v2.1.0

Weekly downloads
12
License
-
Repository
github
Last release
5 years ago

bitreader Build Status

Generic, space efficient (uses Buffer#slice as much as possilbe) parser with sugar for digesting strings, ints, etc. Inherits from stream, implements write and end, and emits data events for easy piping.

Install

$ npm install bitreader-v2

Example

Adapted from streampng

function SuggestedPalette() { this.intialize.apply(this, arguments) }
SuggestedPalette.prototype.initialize = function initialize(data) {
  var colourSize, chunkSize;
  var parser = BitReader(data);

  this.type = 'sPLT'
  this.paletteName = parser.eatString();
  this.sampleDepth = parser.eatUInt(1);
  this.palette = [];

  colourSize = (this.sampleDepth === 16) ? 2 : 1;
  chunkSize = (colourSize === 2) ? 10 : 6

  this.palette = parser.eatRest({ chunkSize: chunkSize }).map(function (entry) {
    var p = BitReader(entry);
    return {
      red: p.eatUInt(colourSize),
      green: p.eatUInt(colourSize),
      blue: p.eatUInt(colourSize),
      alpha: p.eatUInt(colourSize),
      frequency: p.eatUInt(2)
    }
  }.bind(this));
};

API

See the API page on the wiki

Tests

Uses tap for testing. Tested against node 0.6.19 and node 0.8.2.

$ npm test

License

http://wtfpl.org/

2.1.0

5 years ago

2.0.0

5 years ago

0.0.1

5 years ago