Skip to content

decentstack/hypersim-parser

Repository files navigation

hypersim-parser

Build Status JavaScript Style Guide

Streaming ndjson parser and metrics aggregator for hyper-simulator

Install

npm install hypersim-parser

Usage

const { createReadStream } = require('fs')
const { BasicTimeline } = require('hypersim-parser')

const parser = new BasicTimeline()

// Register a custom aggregator
parser.pushReducer('version', (prev, { type, event, seq }) => {
  if (type !== 'custom' && event !== 'block') return 0
  return seq
})

// 'snapshot' event is emitted once for each tick in the simulation's timeline
parser.once('snapshot', (snapshot, iteration) => {
  console.log(snapshot)
  snapshot.version // contains the result the custom reducer/aggregator.
})

// 'close' is fired once all events has been traversed.
parser.once('close', () => console.log('Parsing complete'))

// The parser implements a Writable stream, and accepts
// ndjson in chunks of Buffer | Uint8Array | string

const readable = fs.createReadStream('swarm-log.json')
readable.pipe(parser)

Contributing

Ideas and contributions to the project are welcome. You must follow this guideline.

License

GNU AGPLv3 © Tony Ivanov

About

Log parser and metrics aggregator for hyper-simulator output

Resources

License

Stars

Watchers

Forks

Packages

No packages published