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 🙏

© 2026 – Pkg Stats / Ryan Hefner

protobuf-array-stream

v1.0.1

Published

Stream and decode Protocol Buffer arrays without memory issues - perfect for processing large datasets

Readme

protobuf-array-stream

npm version npm downloads License: MIT

Stream and decode Protocol Buffer arrays without memory issues. While other libraries need the entire message in memory, this one processes array elements directly from the source stream - making it perfect for large datasets.

Why Use This?

  • 💾 Memory Efficient: No need to load entire message in memory
  • 🌊 Streaming: Process array elements directly from source (file, network, etc.)
  • 🎯 Specialized: Built for messages with a repeated field (array)
  • Scalable: Works with arrays of any size, memory usage stays constant

Installation

npm install protobuf-array-stream

Usage

Loading Protocol Definitions

First, you need to load your Protocol Buffer definitions. The library exposes these methods directly from protobufjs for convenience:

import { RepeatedFieldStream } from "protobuf-array-stream";
import { createReadStream } from "fs";

// 1. Load from a .proto file (async)
const root1 = await RepeatedFieldStream.loadRootFromFile(
  "path/to/messages.proto",
);

// 2. Load from a .proto file (sync)
const root2 = RepeatedFieldStream.loadRootFromFileSync(
  "path/to/messages.proto",
);

// 3. Load from a proto definition string
const root3 = RepeatedFieldStream.loadRootFromSource(`
  syntax = "proto3";
  
  message NumberList {
    repeated int32 numbers = 1;
  }
`);

// 4. Load from JSON schema
const root4 = RepeatedFieldStream.loadRootFromJSON({
  nested: {
    NumberList: {
      fields: {
        numbers: {
          id: 1,
          rule: "repeated",
          type: "int32",
        },
      },
    },
  },
});

Real-World Example

You're building an anti-cheat system for your massively multiplayer game. Players are generating TONS of data:

syntax = "proto3";

message GameLog {
  repeated PlayerAction actions = 1;
}

message PlayerAction {
  int64 timestamp = 1;
  string player_id = 2;
  string action = 3;
  Position position = 4;
}

message Position {
  float x = 1;
  float y = 2;
  float z = 3;
}

Process large game session logs efficiently:

const sessionStream = createReadStream("game_session.bin");

const decodeStream = new RepeatedFieldStream({
  root,
  messageName: "GameLog",
});

const analyzeStream = new Transform({
  objectMode: true,
  transform(action, _, callback) {
    const { timestamp, playerId, action: move, position } = action;

    if (move === "shoot" && position.y > 500) {
      console.log(
        `Detected: ${playerId} at height ${position.y} on ${new Date(timestamp.toNumber())}`,
      );
    }

    callback(null, action);
  },
});

sessionStream.pipe(decodeStream).pipe(analyzeStream);

Error Handling

The stream emits errors in these cases:

  • Message type not found in proto definitions
  • Message has no fields or multiple fields
  • Field is not a repeated field
  • Invalid protobuf encoding in input
stream.on("error", (error) => {
  console.error("Stream error:", error.message);
});

API

new RepeatedFieldStream(options)

Creates a new transform stream for processing Protocol Buffer repeated fields.

Options

  • root: Root namespace from protobufjs containing message definitions
  • messageName: Name of the message type to decode

Static Methods

loadRootFromFile(path: string): Promise<Root>

Asynchronously loads Protocol Buffer definitions from a .proto file.

  • path: Path to the .proto file
  • Returns: Promise that resolves to the root namespace

loadRootFromFileSync(path: string): Root

Synchronously loads Protocol Buffer definitions from a .proto file.

  • path: Path to the .proto file
  • Returns: Root namespace

loadRootFromSource(source: string): Root

Loads Protocol Buffer definitions from a string containing proto definitions.

  • source: String containing the proto definitions
  • Returns: Root namespace

loadRootFromJSON(json: object): Root

Loads Protocol Buffer definitions from a JSON object.

  • json: JSON object containing the proto definitions
  • Returns: Root namespace

Requirements

  • Node.js >= 16.0.0
  • Protocol Buffer messages must contain exactly one repeated field

License

MIT License - see the LICENSE file for details