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

gearman-packet

v1.1.0

Published

A streaming gearman parser / emitter suitable for building libraries or servers from

Downloads

38

Readme

gearman-packet

Build Status

A streaming packet parser and emitter for the Gearman protocol and Node.js.

This is a set of transform streams. The parser accepts a stream of buffers of any size and emits objects. The emitter accepts a stream of objects and emits buffers.

For packet types that include an opaque body, the body is provided as a stream by the parser. The emitter can accept either a stream for the body or a buffer or utf-8 string.

Classes

var GearmanPacket = require('gearman-packet');

  • var parser = new GearmanPacket.Parser(options);

This is an stream Transform class, so you can pipe buffers into it and it emits objects. Typical use is to pipe a socket into it and pipe the parser into something that acts on the packet objects. See Packet Objects below for details on what those look like.

The options argument is optional and takes any properties valid for a stream Transform option argument, additionally it also takes:

maxPacketSize - Any packet larger then this number of bytes will be skipped and an error emitted. If you don't specify this then per the protocol spec, packets of up to 2^32 (4,294,967,295) bytes will be accepted. As this would ordinarily cause memory issues, its highly recommended that you set this to something appropriate for your workload.

  • var emitter = new GearmanPacket.Emitter();

This too is a stream Transform class. It accepts objects like those the Parser emits and emits buffers. Typical use is to pipe the emitter into a socket and then write objects to the emitter.

Packet Objects

Packet objects have the following properties:

  • kind: 'request'|'response'|'admin'
  • type: typeobject
  • args: argsobject
  • body: boolean
  • bodySize: integer

Kind should be request or response. Type is one of the objects stored in GearmanPacket.types. Types are simple objects that look like this:

{name: 'SUBMIT_JOB', id: 7, args: ['function','uniqueid'], body: true}

The argsobject's properties must be listed in the type object's args property.

The the parser only produces body's which are streams. The streams it produces have a length attribute telling you how many bytes are in the body-- that is, its the same as the bodySize attribute on the packet object.

The emitter accepts a variety of data types for the body:

  • A buffer, in which case its emitted as-is.
  • A string, which is converted into a buffer and emitted.
  • A stream, which is piped into our output. Streams must either have a length attribute of their own or be included with a packet that has a bodySize attribute.
  • Anything else, in which we call toString() on it and then convert that into a buffer and emit it.

Examples

See example.js in the distribution.

Purpose

This is intended as low-level layer for both a new, streaming-from-the-ground-up gearman client/worker library and also a gearmand-in-node project.