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

pygmylog

v0.1.0

Published

fast binary log encoder

Downloads

2

Readme

about

pygmylog is a simple binary log encoder, its purpose is to simplify the creation of compact binary logs from within nodejs, it encodes rows into transformation streams that can be piped into files or any other writable stream such as Amazon S3.

pygmylog by itself has no dependencies, however, if you wish to use the default encoder you'd need to install protobufjs

As each log also stores its own metadata (schema) it is possible to smoothly change schemas and versions

installation

npm install --save pygmylog

types for default encoder schema

  • object
  • enum - (enum values passed via the enum: property)
  • double
  • float
  • int32
  • uint32
  • int64
  • uint64
  • bool
  • string
  • object_arr
  • enum_arr
  • double_arr
  • float_arr
  • int32_arr
  • uint32_arr
  • int64_arr
  • uint64_arr
  • bool_arr
  • string_arr

by example

pointless read/write to local filesystem example

const fs = require('fs')
const { PassThrough } = require('stream')
const pygmylog = require('pygmylog')

const tmpFilename = '/tmp/pygmylog.test'
const schema = {
  properties: {
    foo: 'int32',
    bar: 'int32_arr',
    myenum: { type: 'enum', enum: ['foo', 'bar', 'foobar'] }
  }
}
const writer = pygmylog.createWriteStream(schema)
const fd = fs.createWriteStream(tmpFilename)

writer.pipe(fd)

fd.on('close', () => {
  const reader = pygmylog.createReadStream()
  const pass = new PassThrough({ objectMode: true })
  pass.on('data', row => {
    console.log(row)
  })
  pass.on('end', () => {
    fs.unlinkSync(tmpFilename)
  })
  fs.createReadStream(tmpFilename).pipe(reader).pipe(pass)
})

writer.write({
  foo: 5,
  bar: [1, 2, 3],
  myenum: 'foo'
})

writer.end()

storing metadata within the headers

const { PassThrough } = require('stream')
const pygmylog = require('pygmylog')

const schema = {
  metadata: { foo: 'bar' },
  properties: {
    foo: 'int32'
  }
}
const writer = pygmylog.createWriteStream(schema)
const reader = pygmylog.createReadStream()

reader.on('ready', data => {
  console.log(data) // { metdata: { foo: 'bar' } }
  const pass = new PassThrough({ objectMode: true })
  pass.on('data', row => {
    console.log(row)
  })
  reader.pipe(pass)
})

writer.pipe(reader)
writer.write({ foo: 5 })
writer.end()

Using your own encoder

const fs = require('fs')
const { PassThrough } = require('stream')
const pygmylog = require('pygmylog')

class UselessEncoder extends pygmylog.Encoder {
  // optionally, you will recieve here the first arguments you've passed to createWriteStream, if this method does not exist the log would not start with a header
  serializeHeaders (headers) {
    return Buffer.from('headersGoHere')
  }
  // optionally, you will recieve here the headers you've serialized in the writer before the first row is processed
  unserializeHeaders (buf) {
    this._myHeadersData = buf.toString('utf8')
  }
  encode (str) {
    // this.headers
    return Buffer.from(str, 'utf8')
  }
  decode (buf) {
    return buf.toString('utf8')
  }
}
const writer = pygmylog.createWriteStream(null, { encoder: UselessEncoder })
const reader = pygmylog.createReadStream({ encoder: UselessEncoder })

const pass = new PassThrough({ objectMode: true })
pass.on('data', entry => {
  console.log(entry) // hellokitty
})

writer.pipe(reader).pipe(pass)
writer.write('hellokitty')
writer.end()

API

pygmylog.createWriteStream(headers, options)

returns a PygmyLogWriter instance

pygmylog.createReadStream(options)

returns a PygmyLogReader instance

pygmylog.Encoder

Encoder class to be extended by custom implementations

PygmyLogWriter.constructor(headers, options = {})

  • options.encoder - class for encoder

pygmyLogWriter.length

returns the total length written so far into the writer in bytes

pygmyLogWriter.write(payload)

pass a row to be encoded into the stream

pygmyLogWriter.end()

ends the writer signaling down the pipe

PygmyLogReader.constructor(options = {})

  • options.encoder - class for encoder

License: MIT