0.0.2 • Published 10 years ago

frax v0.0.2

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

frax

Frame extractor from data stream (e.g. TCP).

Installation

$ npm install frax

Features

  • Extracts frames delimited by frame header (frame length)
  • Supports various frame header lengths (1, 2, 4 bytes)
  • Frame header length 2 is equivalent to RFC 4571.
+--+-------------+--+-------------+--+-------------+
|FH|   Frame 1   |FH|   Frame 2   |FH|   Frame 3   | ...
+--+-------------+--+-------------+--+-------------+
FH: Frame header contains frame length in bytes (big-endian)
    The length does not include the frame header itself.
Frame: Application data.

API

Module method

  • create(headerLen) Creates an instance of frax. The headerLen should either be 1, 2 or 4, or defaults to 2 otherwise.

Instance method

  • frax.input(buf) - Input stream data. The buf is of type Buffer.
  • frax.headerSize (getter) - Returns frame header size used by the instance.
  • frax.reset() - Reset the internal state. Probably useless expect for test purposes.
  • Event: 'data' - Emitted when a complete frame is ready. The argument buf will be a Buffer.

Example

var frax = require('frax').create();

// Set up data event handler
frax.on('data', function (frame) {
    console.log('%d bytes of frame received', frame.length);
});

// Pass incoming data into frax directly.
soc.on('data', function (buf) {
    frax.input(buf);
});