Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enobufs/frax
Frame extractor from data stream.
https://github.com/enobufs/frax
Last synced: 10 days ago
JSON representation
Frame extractor from data stream.
- Host: GitHub
- URL: https://github.com/enobufs/frax
- Owner: enobufs
- Created: 2014-07-18T19:42:06.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-25T00:12:03.000Z (over 10 years ago)
- Last Synced: 2024-04-14T06:01:41.138Z (7 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.```text
+--+-------------+--+-------------+--+-------------+
|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
```js
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);
});```