hypersim-parser

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i hypersim-parser

Weekly Downloads

2

Version

1.0.0

License

AGPL-3.0-or-later

Unpacked Size

44.2 kB

Total Files

6

Last publish

Collaborators

  • telamon