Coder Social home page Coder Social logo

stream-frame's Introduction

StreamFrame Build Status

NPM

StreamFrame is a stream framing library for node.js.

Install

npm install stream-frame --save

Installing the latest version

$ npm install git+https://github.com/majimboo/stream-frame.git

Usage

var StreamFrame = require('stream-frame');

var server = net.createServer(function (socket) {
  var B = new StreamFrame();
  B.wrap(socket);

  B.on('data', function(data) {
    console.log(data);
  });
});

You can also pass the socket as a parameter of StreamFrame().

var B = new StreamFrame(socket);
B.on('data', data_handler);

Options

  • lengthSize (default: 2) - The length in bytes of the prepended message size.
  • bigEndian (default: false) - The byte order of the prepended length.
  • offset (default: 0) - The offset where the packet size can be found.
  • ignore (default: false) - Will not try to frame the message.
var StreamFrame = require('stream-frame');
var B = new StreamFrame();

B.set('lengthSize', 1); // uint8
B.set('lengthSize', 2); // uint16
B.set('lengthSize', 4); // uint32

B.set('offset', 2);    // size starts at 3rd byte.
B.set('ignore', true); // will emit data immedietely without framing.

B.set('bigEndian', true);  // uses bigEndian order
B.set('bigEndian', false); // uses default little endian order

Benchmark

v 0.0.3
StreamFrame x 623,238 ops/sec ±1.72% (87 runs sampled)

v 0.0.4
StreamFrame x 886,578 ops/sec ±0.56% (90 runs sampled)

stream-frame's People

Contributors

majimboo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.