Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fingi-cmd

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fingi-cmd

Fingi command protocol parser and serializer.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

FINGI-CMD

Install with

$ npm i fingi-cmd --save

USAGE

The package exports the Command class, a parse method and a Stream which is a Duplex stream that works on Command instances.

COMMAND class

Create by invoking the constructor with new and passing the desired command properties.

var Command = require('fingi-cmd').Command;
var cmd = new Command({ action: 'HELLO' });

Properties include:

  • nonce - (number) The nonce counter.
  • source - (string array) The command source (or origin.)
  • action - (string) The action to carry out.
  • args - (string array) Arguments

Check with the official Fingi protocol description for more information.

When you already have a Command instance, these 2 methods may be of interest:

cmd.sign(secret)

Signs the entire command line using the HMAC-SHA1 algorithm and append the resulting signature digest as the last argument.

cmd.toString()

Returns correct protocol represenation of the command as a string ready to be sent onto the wire.

STREAM

The exported Stream is an instance of node core's Duplex object-mode stream which automatically parses incoming data into Command instances and then allow send()-ing out commands to the wire.

var CmdStream = require('fingi-cmd').Stream;
var commands = new CmdStream();

Receiving commands

To receive commands, pipe your raw incoming stream into the CmdStream and listen for the command event. The chunker module is also recommended to ensure that the stream always receives a full line.

process.stdin.pipe(commands);
commands.on('command', function(cmd) {
  console.log('receive:', cmd.action());
});

Or when using with chunker:

var chunker = new (require('chunker'))({ matcher: '\r\n' });
process.stdin.pipe(chunker).pipe(commands);

// commands.on('command')... as usual

Sending commands

Send commands by using the send() method, passing in the Command instance to send.

commands.pipe(process.stdout);

// send PINGs every second.
setInterval(function() {
  commands.send(new Command({ action: 'PING' }));
}, 1000);

PARSE

Optionally, you may have a string representation that you would like to parse by yourself. You can do this by using the exported parse() function:

var parse = require('fingi-cmd').parse;

var input = '1000 server-name 9.9.99 | HELLO device\r\n';
var cmd = parse(input);

console.log(cmd.source[0]); // prints "server-name"

LICENSE

MIT. See the LICENSE file for the full license text.

Keywords

FAQs

Package last updated on 28 Nov 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc