Fast, lightweight, and extensible message framing over streams
npm install fringeFringe
===

Fast, lightweight, and extensible message framing over streams.
```
npm install --save fringe
By default, fringe encodes your input buffer with the string FRINGEUInt32BE
plus the byte length of the input buffer encoded as .
#### Hello world:
`js
const { Encoder, Parser } = require('fringe');
const encoder = new Encoder();
const parser = new Parser();
encoder.pipe( parser );
parser.on( 'message', buffer => console.log( buffer.toString('utf8') ) );
encoder.write('hello');
encoder.write('world');
`
When a complete message is received, Parser will emit two events:
#### data
The standard Node.js data events for streams. The argument passed to your
callback will be a Buffer of the original message payload.
#### message
The argument passed to the message event will be the return value of theParser instance's translate method (see below).
By default, this value will be identical to the Buffer passed to the datatranslate
callback – but is useful for situations where may return a parsed
object.
Encoder and Parser each accept two arguments:
#### format
An object containing formatting options for the message
###### prefix
A string that will be prepended to each message (may be an empty string).
Defaults to FRINGE.
###### lengthFormat
The binary format that the payload length will be stored as. Options are
UInt8, UInt16BE, UInt16LE, UInt32BE, and UInt32LE. Defaults toUInt32BE.
###### maxSize
The maximum acceptable payload length in bytes. Defaults to 100 MB
(1024 1024 100).
#### options
Options to be passed directly to the underlying Transform stream.
Encoder and Parser may each be sub-classes with custom translate methods.
#### Encoder translate
Accepts any value and must return a string or Buffer.
An example translate function to accept an object and output a JSON string:
`js`
translate( obj ) {
return JSON.stringify( obj );
}
#### Parser translate
Accepts a string or Buffer and may return any value.
An example translate function to accept a Buffer and output an object:
`js``
translate( buffer ) {
return JSON.parse( buffer.toString('utf8') );
}