Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

lob-enc

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lob-enc

Length-Object-Binary Packet Encoding

latest
Source
npmnpm
Version
0.0.17
Version published
Maintainers
1
Created
Source

Length-Object-Binary (LOB) Packet Encoding (javascript)

This module will encode and decode LOB packets to/from JSON and Buffers.

Install: npm install lob-enc

Primary usage:

var lob = require('lob-enc');
var json = {
  "type":"test",
  "foo":["bar"]
};
var body = new Buffer("any binary!");
var bin = lob.encode(json, body));
// bin will be a buffer with json and body encoded

var packet = lob.decode(bin);
// packet.json == json, and packet.body == body

// do both encode and decode together, for convenience
var packet = lob.packet(json, body);

// object validator
var bool = lob.isPacket(packet);

Also supports reading a packet in a streaming mode:

var stream = lob.stream(function(packet, cbDone){
  // packet.json is the complete header
  // any packet.body will be subsequently streamed
  cbDone();
});

var es = require('event-stream');
stream.pipe(es.wait(function(err, body){
  // body is the body of the packet
}));

// test stream in fragments
var bin = new Buffer('001d7b2274797065223a2274657374222c22666f6f223a5b22626172225d7d616e792062696e61727921','hex');
es.readArray([bin.slice(0,10),bin.slice(10,20),bin.slice(20,30),bin.slice(30)]).pipe(stream);

Packets can be read and written in chunks:

// args.ack = true will only send one chunk until another is read, blocking/acking
var chunk = lob.chunking(args, function cbPacket(err, packet){ });

chunk.pipe(socket); // chunks are written to socket
socket.pipe(chunk); // incoming socket data is read back as chunks

chunk.send(packet); // send a packet as one or more chunks

Packets can be cloaked:

var cloaked = lob.cloak(packet);
var packet = lob.decloak(cloaked);
// packet.cloaked = # of rounds

Keywords

lob encoding

FAQs

Package last updated on 02 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts