npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dltreader

v0.0.14

Published

Diagnostic Log and Trace format reader

Downloads

111

Readme

Overview

This library helps decode DLT logs (Diagnostic Log and Trace):

  • from stream (being connected to DLT demon)
  • from file

Installation

npm install dltreader --save

Usage

Decode file

Example of file reading.

import * as DLT from 'dltreader';
import * as fs from 'fs';

const file: string = 'some_logs_file.dlt';

// Create transform object
// Bellow see more about options for DLT transform object
const tranform : DLT.TransformStream = new DLT.TransformStream({}, { stringify: true, datetime: true });

// Create null writable stream (we do not want in this example to write any data, it's just reading.
// If you need write data, just create real writable stream
const writer: DLT.NullWritableStream = new DLT.NullWritableStream(true);

// Or real sctream
/*
const writer: fs.WriteStream = fs.createWriteStream('some_desination_file.txt');
*/

// Create file reader (for original DLT file)
const reader: fs.ReadStream = fs.createReadStream(file);

// This event is triggered: when chunk is read and decoded
tranform.on(DLT.TransformStream.Events.chunk, (bytes, packets) => {
    console.log(`Has beed read: ${(bytes / 1024 / 1024).toFixed(2)}Mb; detected ${packets} packets`);
});

// Listen moment of complite to read file
reader.on('end', () => {
    console.log(`Done`);
});

// Start reading
reader.pipe(tranform).pipe(writer, { end: false });

Run-time decode stream

Example of reading DLT-demon

import * as Net from 'net';
import * as DLT from 'dltreader';

const DLT_DEMON_IP = '127.0.0.1';
const DLT_DEMON_PORT = 3490;


// Create DLT buffer
const dltbuffer = new DLT.Buffer();

// Create object to count incoming packages
const counters = {
    packets: 0,
    pending: 0,
    size: 0,
    errors: 0,
};

// Array to store errors
const errors: string[] = [];

// "packet" event triggers with each decoded package
dltbuffer.on(DLT.Buffer.Events.packet, (packet: DLT.IPacketData) => {
    counters.size += packet.length;
    console.log(`Packet: ${packet.length} bytes;\tWSID: ${packet.standardHeader.WSID};\tWTMS: ${packet.standardHeader.WTMS};\tWEID: ${packet.standardHeader.WEID};\tEID: ${packet.standardHeader.EID};\tMCNT: ${packet.standardHeader.MCNT}`);
    console.log(`Packages read: ${++counters.packets}; ${counters.size} bytes; errors: ${counters.errors}`, 'done');
});

// "error" event triggers if decoding of package was failed. Process of listening / decoding isn't stopped
dltbuffer.on(DLT.Buffer.Events.error, (error: DLT.Error) => {
    if (error.code !== DLT.EErrorCode.HEADER_MIN_LEN && error.code !== DLT.EErrorCode.PACKET_LEN) {
        errors.push(`Error: ${error.message}. Code: ${error.code}.`);
        console.log(`${errors.join('\n')}`, 'errors');
        counters.errors += 1;
    } else {
        console.log(`Packages pendin happens: ${++counters.pending}`, 'pendins');
    }
});

// Create connection to DLT demon
const socket: Net.Socket = Net.connect(DLT_DEMON_PORT, DLT_DEMON_IP, () => {
	console.log('Connected to DLT daemon.');
});

// Start listening connection
socket.on('data', (chunk: Buffer) => {
	dltbuffer.add(chunk);
});

// Listen errors of connection
socket.on('error', (error: Error) => {
	console.error(`Connection error: ${error.message}`);
});

// Do not forget to close application with closing of connection
socket.on('close', () => {
	process.exit();
});