New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ais-stream-decoder

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ais-stream-decoder

AIS/NMEA decoder with native Node.js stream interface (TypeScript/JavaScript)

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

AIS Stream Decoder

AIS/NMEA decoder with native stream interface for Node.js.

NPM Version CI Tests

Installation

This is a Node.js module available through the npm registry.

Installation is done using the npm install command:

$ npm install ais-stream-decoder

Features

  • Currently supports message types 1,2,3,4,5,18,24 (more to come) and partially supports message type 8 (inland static and voyage data)
  • Handles multi-part messages out of the box
  • Streaming API implemented as a Node.js transform stream
  • Returns nicely formatted JSON messages
  • Written in TypeScript

Usage

Decode a single line of data:

import AisDecoder from 'ais-stream-decoder';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const nmea = '!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41';
aisDecoder.write(nmea);

=>

{"type":1,"channel":"B","repeat":0,"mmsi":205278090,"navStatus":0,"rateOfTurn":null,"speedOverGround":8.4,"accuracy":true,"lon":4.73319,"lat":51.725665,"courseOverGround":260.1,"heading":null,"utcSecond":37,"specialManoeuvre":0,"raim":true,"radio":59916,"sentences":["!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41"]}

Handles multi-part messages like a pro:

import AisDecoder from 'ais-stream-decoder';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const part1 =
  '!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28';
const part2 = '!AIVDM,2,2,7,A,PBp888888888880,2*79';

aisDecoder.write(part1);
aisDecoder.write(part2);

=>

{"type":5,"channel":"A","repeat":0,"mmsi":525200930,"aisVersion":2,"imo":9835915,"callsign":"YCKT2","name":"AKRA 102","typeAndCargo":80,"dimBow":67,"dimStern":33,"dimPort":19,"dimStarboard":1,"epfd":1,"etaMonth":9,"etaDay":7,"etaHour":16,"etaMinute":0,"draught":4.2,"destination":"ID_MERAK","dte":false,"sentences":["!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28","!AIVDM,2,2,7,A,PBp888888888880,2*79"]}

Use it to read and decode NMEA line-by-line from a file:

import AisDecoder from 'ais-stream-decoder';
import {createReadStream} from 'fs';
import {resolve} from 'path';
import {createInterface} from 'readline';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const fileStream = createReadStream(
  resolve(__dirname, './examples/messages.txt')
);
const readLine = createInterface(fileStream);
readLine.on('line', line => aisDecoder.write(line));

We all love pipes! ❤

import AisDecoder from 'ais-stream-decoder';
import split from 'split';
import {createReadStream} from 'fs';
import {resolve} from 'path';

const fileStream = createReadStream(
  resolve(__dirname, './examples/messages.txt')
);
const aisDecoder = new AisDecoder({silent: true});

fileStream
  .pipe(split())
  .pipe(aisDecoder)
  .on('data', decodedMessage => {
    console.log(decodedMessage);
  });

License

MIT

Keywords

FAQs

Package last updated on 19 Jan 2021

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